I am write a simulation for get true Velocity of a harmonic oscillator system as
Where P=[p1 p2;p2 p3] can find using Rung-Kutta Integration method with P(0)=[1 0; 0 1]
Now, I want to write matlab code to get the true postion z
of the system and estimate x inwhich x=[x1 x2]'. This is my code to find x and z. However, the result is not correct. Could you help me to modify it. This is my matlab code
function z=getPos(x)
%% Function to get velocity
v=0+1*randn; %r=1;
z=[0 1]*x+v;
return
This is my result
Let see help me is correct implement for the solution. Thank you
Your code can return a negative value as randn is a normally distributed random number with standard deviation 1. In theory this could return any number and there is ~15% chance it will be less than -1.
You are also correct than you should update x at each step. I would take x as an input into getPos and xdot as an output. Then add another step to update the position.