필터 지우기
필터 지우기

Plotting the solution to a system of ODE on an interval that doesn't contain the initial time

조회 수: 2 (최근 30일)
I have to plot the solution to the system of ODEs
with the initial conditions on the time interval [100,200]. I am trying to do this somehow unusual, by solving the system separately on [0,100] and [100,200].
For the interval [0,100] I used the function in z:
function dzdt=odefunzz(t,z)
dzdt=zeros(2,1);
dzdt(1)=z(2);
dzdt(2)=-z(1);
end
the command lines
tspan = [0 100];
z0 = [0.1 0.1];
[t,z] = ode45(@(t,z) odefunzz(t,z), tspan, z0);
plot(t,z(:,1),'r',t,z(:,2),'b');
and I easily obtained the plotting of the solution on .
For the second interval I used a similar function, but in in w:
function dwdt=odefunww(t,w)
dwdt=zeros(2,1);
dwdt(1)=w(2);
dwdt(2)=-w(1);
end
and similar command lines,
tspan = [0 100];
w0 = [z(1) z(2)];
[t,w] = ode45(@(t,w) odefunww(t,w), tspan, w0);
plot(t,w(:,1),'r',t,w(:,2),'b');
Is the command
w0 = [z(1) z(2)];
correct? Because I need to use the values of the first solution as initial conditions for the system on . Or, more exactly, does the vector (at the end of the first command lines) represent the values of the solution z (found on the interval ) at the endpoint ?

채택된 답변

Star Strider
Star Strider 2020년 1월 1일
Is the command
w0 = [z(1) z(2)];
correct?
No, not if you want to do what you indicated. If you want to use the last values of ‘z’ as the intiial conditions for ‘w’, I would do something like this instead:
odefunzz = @(t,z) [z(2); -z(1)];
odefunww = @(t,w) [w(2); -w(1)];
tspan = [0 100];
z0 = [0.1 0.1];
[t,z] = ode45(@(t,z) odefunzz(t,z), tspan, z0);
figure
plot(t,z(:,1),'r',t,z(:,2),'b');
tspan = [100 200];
w0 = [z(end,1) z(end,2)];
[t,w] = ode45(@(t,w) odefunww(t,w), tspan, w0);
figure
plot(t,w(:,1),'r',t,w(:,2),'b');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by