How to use ODE45 to solve a second order system of equations?
조회 수: 2 (최근 30일)
이전 댓글 표시
I need to solve:
d^2t/ds^2 = 0
d^2r/ds^2 = 0
I know that this is a straight line, however I'm going to extrapolate this to another example.
So what I have is
function dy = myode(t,y)
dy = zeros(2,1);
dy(1) = y(2);
dy(2) = 0;
I can call this buy using
[T,Y] = ode45(@myode,0:5,[1;0])
Any help is appreciated!
Edit:
yin=[0 4]; % initial values
time=[0 5];
[x,y]=ode45(@myode,time,yin);
plot(x,y)
where myode is
function dy=myode2(~,y)
dy=[0;0];
dy(1)=y(2);
dy(2)= 0;
Now the problem is the plot. I get the correct straight line(blue) but what is this pesky red line at y = 4?
댓글 수: 0
답변 (1개)
Torsten
2016년 2월 9일
It's the derivative of y (y(2)) which is identically 4.
If you only want to plot y, use
plot(x,y(:,1));
Best wishes
Torsten.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!