In: Advanced Math
I have to finish the code given by my diff eq professor to analyze the lorenz function at different initial conditions and different values for p. I am not sure how to input the lorenz function in the way the code is set up.
Here is the code provided for matlab:
function lorenz
s = 10;
b = 8/3;
p = 0.15;
y = @(t,x) [ ; ; ]; % you are responsible for entering the
lorenz system here
T = [0 200]; % sets the time interval; no need to edit
x0 = [1 1 1]; % initial conditions; this can and should be
editied
[t,x] = ode45(y,T,x0); % ode solver; do not edit
plot3(x(:,1),x(:,2),x(:,3),'r') % plots 3d solution for entered
conditions
grid on
%%Matlab code for Lorenz equation solution
clear all
close all
%value for alpha beta and eta
s=10; p=0.15; b=(8/3);
%and initial condition of y
y10=1; y20=1; y30=1;
%initial value for t
t0=0;
%t end values
tend=200;
y0=[y10;y20;y30];
%minimum and maximum time span
tspan=[t0 tend];
%Solution of ODEs using
ode45 matlab function
sol= ode45(@(t,y)
odefcn1(t,y,s,p,b), tspan, y0);
t1 =
linspace(tspan(1),tspan(end),100001);
%yy is the corresponding
x y v and z
yy1 =
deval(sol,t1);
figure(1)
plot3(yy1(1,:),yy1(2,:),yy1(3,:))
xlabel('y1');ylabel('y2');zlabel('y3')
title('3d line plot for Lorenz attractor initial cond [1 1 1] and
p=0.15')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%value for alpha beta and eta
s=10; p=10; b=(8/3);
%and initial condition of y
y10=1; y20=1; y30=1;
%initial value for t
t0=0;
%t end values
tend=200;
y0=[y10;y20;y30];
%minimum and maximum time span
tspan=[t0 tend];
%Solution of ODEs using
ode45 matlab function
sol= ode45(@(t,y)
odefcn1(t,y,s,p,b), tspan, y0);
t1 =
linspace(tspan(1),tspan(end),100001);
%yy is the corresponding
x y v and z
yy1 =
deval(sol,t1);
figure(2)
plot3(yy1(1,:),yy1(2,:),yy1(3,:))
xlabel('y1');ylabel('y2');zlabel('y3')
title('3d line plot for Lorenz attractor initial cond [1 1 1] and
p=10')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%value for alpha beta and eta
s=10; p=20; b=(8/3);
%and initial condition of y
y10=1; y20=2; y30=1;
%initial value for t
t0=0;
%t end values
tend=200;
y0=[y10;y20;y30];
%minimum and maximum time span
tspan=[t0 tend];
%Solution of ODEs using
ode45 matlab function
sol= ode45(@(t,y)
odefcn1(t,y,s,p,b), tspan, y0);
t1 =
linspace(tspan(1),tspan(end),100001);
%yy is the corresponding
x y v and z
yy1 =
deval(sol,t1);
figure(3)
plot3(yy1(1,:),yy1(2,:),yy1(3,:))
xlabel('y1');ylabel('y2');zlabel('y3')
title('3d line plot for Lorenz attractor initial cond [1 2 1] and
p=20')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%value for alpha beta and eta
s=10; p=20; b=(8/3);
%and initial condition of y
y10=1; y20=5; y30=1;
%initial value for t
t0=0;
%t end values
tend=200;
y0=[y10;y20;y30];
%minimum and maximum time span
tspan=[t0 tend];
%Solution of ODEs using
ode45 matlab function
sol= ode45(@(t,y)
odefcn1(t,y,s,p,b), tspan, y0);
t1 =
linspace(tspan(1),tspan(end),100001);
%yy is the corresponding
x y v and z
yy1 =
deval(sol,t1);
figure(4)
plot3(yy1(1,:),yy1(2,:),yy1(3,:))
xlabel('y1');ylabel('y2');zlabel('y3')
title('3d line plot for Lorenz attractor initial cond [1 5 1] and
p=20')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%value for alpha beta and eta
s=10; p=28; b=(8/3);
%and initial condition of y
y10=1; y20=1; y30=1;
%initial value for t
t0=0;
%t end values
tend=200;
y0=[y10;y20;y30];
%minimum and maximum time span
tspan=[t0 tend];
%Solution of ODEs using
ode45 matlab function
sol= ode45(@(t,y)
odefcn1(t,y,s,p,b), tspan, y0);
t1 =
linspace(tspan(1),tspan(end),100001);
%yy is the corresponding
x y v and z
yy1 =
deval(sol,t1);
figure(5)
plot3(yy1(1,:),yy1(2,:),yy1(3,:))
xlabel('y1');ylabel('y2');zlabel('y3')
title('3d line plot for Lorenz attractor initial cond [1 1 1] and
p=28')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%value for alpha beta and eta
s=10; p=28; b=(8/3);
%and initial condition of y
y10=1; y20=5; y30=1;
%initial value for t
t0=0;
%t end values
tend=200;
y0=[y10;y20;y30];
%minimum and maximum time span
tspan=[t0 tend];
%Solution of ODEs using
ode45 matlab function
sol= ode45(@(t,y)
odefcn1(t,y,s,p,b), tspan, y0);
t1 =
linspace(tspan(1),tspan(end),100001);
%yy is the corresponding
x y v and z
yy1 =
deval(sol,t1);
figure(6)
plot3(yy1(1,:),yy1(2,:),yy1(3,:))
xlabel('y1');ylabel('y2');zlabel('y3')
title('3d line plot for Lorenz attractor initial cond [1 5 1] and
p=28')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Function for evaluating the ODE
function dydt = odefcn1(t,y,s,p,b)
eq1 = s*(y(2)-y(1));
eq2 = y(1)*(p-y(3))-y(2);
eq3 = y(1)*y(2)-b*y(3);
%Evaluate the ODE for our present problem
dydt = [eq1;eq2;eq3];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%