how can i resolve this equation Runge kutta method
이전 댓글 표시
y''+1=0
ddy/ddt + 1 =0
how can i resolve this equation with runge kutta method
댓글 수: 6
James Tursa
2020년 1월 22일
You can use the ode45 function.
doc ode45
If you need to code a Runge Kutta method yourself, please show what you have done so far and tell us what problems you are having.
adem ski
2020년 1월 22일
Jim Riggs
2020년 1월 22일
ode45 is a Runge-Kutta method (Dormand-Prince)
adem ski
2020년 1월 22일
James Tursa
2020년 1월 22일
@adem: You need to show us what you have done so far and then we can help you with your code.
adem ski
2020년 1월 22일
답변 (2개)
James Tursa
2020년 1월 22일
편집: James Tursa
2020년 1월 23일
You've got a 2nd order equation, so that means you need a 2-element state vector. The two states will be y and y'. All of your code needs to be rewritten with a 2-element state vector [y;y'] instead of the single state y. I find it convenient to use a column vector for this. So everywhere in your code that you are using y, you will need to use a two element column vector instead. E.g., some changes like this:
y = zeros(2,numel(t)+1); % pre-allocate the solution, where y(:,m) is the state at time t(m)
:
y(:,1) = [1;0]; % need to initialize two elements at first time, position and velocity
:
f = @(t,y)[y(2);-1]; % [derivative of position is velocity; derivative of velocity is acceleration = -1]
:
k1 = h*feval(f, t , y(:,m) ); % changed y(m) to y(:,m)
Also, you have a bug in the line that combines the k's ... you need (1/6)* instead of (1/6)+
Make an effort at implementing these changes and then come back with any problems you continue to have.
카테고리
도움말 센터 및 File Exchange에서 Runge Kutta Methods에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!