Plotting the solution to a system of ODE on an interval that doesn't contain the initial time
Show older comments
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:
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
?
. Or, more exactly, does the vector
(at the end of the first command lines) represent the values
) at the endpoint
?Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!