I want to solve this equation by Runga kutta method 4.
d2xd/dt2+0.2dx/dt-2.45xd+0.2908xp=
with intial condition
t=to=0
xd=1
xp=0
from t=0 to 100
Best Answer
Firstly, you can't have spaces in the name of the m-file. Remove them.
Secondly, remember "length" not "lenght".
Thirdly, pass parameters to the functions in the same order in which you define the functions.
Fourthly, make use of Matlab's error messages!
Here is a working code, but it produces nonsense because of the third point above. Put the parameters in the right order and you might get something sensible.
%input paramters
h=1;
t=1:h:100;
xd=zeros(1,length(t)); %%%%% length not lenght
xp=zeros(1,length(t)); %%%%% length not lenght
vd=zeros(1,length(t)); %%%%% length not lenght
vp=zeros(1,length(t)); %%%%% length not lenght
xdo=1;
vdo=0;
xpo=-1;
vpo=0;
xd(1)=xdo; %%%%% These next four lines must come after the previous four,
vd(1)=vdo; %%%%% and array indices start at 1 not 0 in Matlab.
Best Answer