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

5 ビュー (過去 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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by