Need help with my MATLAB code for the bold question at the bottom please. New to
ID: 663336 • Letter: N
Question
Need help with my MATLAB code for the bold question at the bottom please. New to this, something is wrong and I'm too tired to find it. Thank you in advance. (I tried to include enough information -- if I forgot something, please let me know).
(copy and paste matlab2ab(12,27,7/2) in command window to run the code)
Context:
This Lorenz system is notable for exhibiting chaos. In a chaotic system, two solutions that start very near to one another can wind up with very different outcomes. Although there is no random term in the equation (we say the system is deterministic), nonetheless small changes in a state can produce significant and unpredictable changes in the future behaviour. For instance, the weather is typically considered to follow chaotic dynamics.
To see this chaos, you are to consider two nearby numerical solutions to this system. Solution 1 will be identical to the one in the first question, that is x(0) = 10, y(0) = 5, and z(0) = 13. For Solution 2, take as initial conditions x(0) = 10 + 0.02, y(0) = 5 + 0.02, and z(0) = 13 + 0.02. Use ode45 to solve for each solution numerically.
We will want to plot these solutions only for around the time t* when the two solutions start to significantly diverge from one another. For the purposes of this problem, we will take the time t* of significant divergence to be the first time when the solutions are more than a distance of 20 apart.
Find a vector which consists of the distance between Solution 1 and Solution 2 at each time point.
Use a for or while loop to determine which row in your distance vector is the first row when the distance is greater than 20 and what time t* (in seconds, correct to 3 decimals) does your row correspond to?
Here is the code so far:
function [t, x, y, z] = matlab2ab(sigma, r, b)
close all;
clc;
x0 = [11+0.02; 5+0.02; 18+0.02];
[t, xvec] = ode45(@f,[0: 0.01 :20], x0);
x = xvec(:, 1);
y = xvec(:, 2);
z = xvec(:, 3);
% Plot of the solution
plot3(x,y,z)
xlabel('x')
ylabel('y')
zlabel('z')
title('lala')
grid on
figure
plot(t,x)
xlabel('t')
ylabel('x(t)')
title('name')
grid on
figure
plot(t,y,'b', t,z,'r')
title('name');
legend('y', 'z');
xlabel('t');
ylabel('y and z');
grid on
function xdot = f(t,x)
xdot= [ sigma * (x(2) - x(1)); ...
x(1)*(r - x(3)) - x(2); ...
x(1) * x(2) - b * x(3) ];
end
%this is where I need help ... Need to compare x0 = [11; 5; 18]; to x0 = [11+0.02; 5+0.02; 18+0.02];
Find a vector which consists of the distance between Solution 1 and Solution 2 at each time point.
Use a for or while loop to determine which row in your distance vector is the first row when the distance is greater than 20 and what time t* (in seconds, correct to 3 decimals) does your row correspond to?
minvalue=20;
for t = 0:Inf
value = sqrt(sum((x(t,:)-x0').^2));
if value > minvalue
minvalue = value;
tmin = t
end
end
tmin
end
Explanation / Answer
I thing there is no any error to debug.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.