I am trying to learn how to use MATLAB to solve a system of differential equations (Lorenz equations) and plot each solution as a function of t
X’ = −σx + σy
Y’ = ρx − y − xz
Z’ = −βz + xy
where σ = 10
, β = 8/3
, and ρ = 28
, as well as x(0) = −8
, y(0) = 8
, and z(0) = 27
.
Here is the code that I am using:
function xprime = example(t,x)
sig = 10;
beta = 8/3;
rho = 28;
xprime = [-sig*x(1) + sig*x(2);
rho*x(1) - x(2) - x(1)*x(3);
-beta*x(3) + x(1)*x(2)];
x0 = [-8 8 27];
tspan = [0 20];
[t,x] = ode45(@example, tspan, x0);
figure
plot(t,x(:,1)), hold on
plot(t,x(:,2)), hold on
plot(t,x(:,3)), hold off
However, this generates an error, how do I fix this? I am not sure what input arguments are missing or where I am going wrong. I appreciate any help, thanks.
Not enough input arguments.
Error in example (line 9) xprime=[-sigx(1) + sigx(2); rho*x(1) - x(2) - x(1)x(3); -betax(3) +
x(1)*x(2)];