Display divergence of trajectories

3 views (last 30 days)
Jambalya
Jambalya on 21 Nov 2022
Answered: William Rose on 21 Nov 2022
I need to show the spread of this system after 1000 iterations. I’m assuming I would just change time to 1000. Is this correct? Also, I need to set hold on after the first run to show both the first and second to display the divergence of the trajectory in different colors. I have no clue how to do this.
if true
% code
end

Answers (1)

William Rose
William Rose on 21 Nov 2022
PLease attach code as .m files instead of attaching screenshots of code.
You say "after 1000 interations". I am not sure what you mean by iterations. Do you mean after 1000 seconds? Or after 1000 "loops"? 1000 loops will be difficult to count because sometimes the trajectory goes from one side to the other, and sometimes it doesn't. ode45() does not use a fixed stepsize, so I suspect you do not mean 1000 steps of the integrator ode45().
You say you will do a first run and a second run. What will differ from run 1 to run 2?
I will assume that by "after 1000 iterations" you mean "after 1000 units of time". Then simulate the system for time=1010 units of time . I would first modify lorenz_demo.m so that it returns vectors t and x. Therefore its first line would become
function [t,x] = lorenz_demo(time)
and I would comment out the lines of lorenz_demo() that make a plot. Then your main program can be something like this:
[t1,x1]=lorenz_demo(1020); %run 1
plot3(x1(t1>1000,1),x1(t1>1000,2),x1(t1>1000,3),'-r');
%Line above makes 3D plot of run 1 results after t=1000, in red.
xlabel('X'); ylabel('Y'); zlabel('Z'); grid on
hold on
%Make any other desired changes before run 2.
[t2,x2]=lorenz_demo(1020); %run 2
plot3(x2(t2>1000,1),x2(t2>1000,2),x2(t2>1000,3),'-b');
%Line above makes 3D plot of run 2 results after t=1000, in blue.
legend('Run 1','Run 2');
Try it. Good luck.

Tags

Community Treasure Hunt

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

Start Hunting!