lorentz simulation error what is the error please help
Mostrar comentarios más antiguos
clear
ti = 0; % set the initial value of t
tf = 130; % set the final value of t
dt = 0.01;
% set the step size
xo = 1.0; yo = 1.0; zo = 1.0;
% set the initial conditions (arbitrarily)
t = [ti : dt : tf];
% creating a vector of the nodal points
N = length(t);
% calculate the number of nodes
r(:,1) = [xo ; yo ; zo];
% creating a vector with the initial conditions
for i = 1: N-1
k1 = dt * f( t(i) , r(:,i) );
k2 = dt * f( t(i)+dt/2 , r(:,i)+k1/2);
k3 = dt * f( t(i)+dt/2 , r(:,i)+k2/2);
k4 = dt * f( t(i)+dt , r(:,i)+k3);
r(:,i+1) = r(:,i)+(k1+2*k2+2*k3+k4)/6;
end
figure(1),plot(t,r(1,:),t,r(2,:),t,r(3,:))
figure(2),plot3(r(1,:),r(2,:),r(3,:)),grid on
clear t
x=r(1,3002:N)';
y=r(2,3002:N)';
z=r(3,3002:N)';
clear r
figure(3),plot3(x,y,z),grid on
function [rdot] = f (t,r)
sigma = 10;
rho = 28; beta = 8/3;
rdot=zeros(3,1);
rdot(1) = sigma*(r(2)-r(1));
rdot(2) = rho*r(1)-r(2)-r(1)*r(3);
rdot(3) = r(1)*r(2)-beta*r(3);
end
IM getting error message saying 'f' requires more input arguments to run :f(t,r) it says enter input arguments what is the error please and how it should be wrriten many thanks
3 comentarios
Torsten
el 12 de Jul. de 2023
Works for me (see above).
Hi @Numan
Because in this f(t, r) function, the rdot() operations involve x, but no defined variable 'x' or recognized function 'x' is found throughout the code.
function [rdot] = f(t, r)
sigma = -0.38;
alpha = 5; beta = -10;
rdot=zeros(3,1);
rdot(1) = alpha * x - y * z;
rdot(2) = beta * y + x * z;
rdot(3) = sigma * z + (x * y) / 3;
end
Respuestas (1)
Hi @Numan
I have fixed the code in f(t, r) function, by adding the definitions for x, y, z. Check if the results are expected.
ti = 0; % set the initial value of t
tf = 130; % set the final value of t
dt = 0.01;
% set the step size
xo = 5.0; yo = 10.0; zo = 10.0;
% set the initial conditions (arbitrarily)
t = [ti : dt : tf];
% creating a vector of the nodal points
N = length(t);
% calculate the number of nodes
r(:,1) = [xo ; yo ; zo];
% creating a vector with the initial conditions
for i = 1: N-1
k1 = dt * f( t(i) , r(:,i) );
k2 = dt * f( t(i)+dt/2 , r(:,i)+k1/2);
k3 = dt * f( t(i)+dt/2 , r(:,i)+k2/2);
k4 = dt * f( t(i)+dt , r(:,i)+k3);
r(:,i+1) = r(:,i)+(k1+2*k2+2*k3+k4)/6;
end
figure(1),plot(t,r(1,:),t,r(2,:),t,r(3,:))
figure(2),plot3(r(1,:),r(2,:),r(3,:)),grid on
clear t
x=r(1,3002:N)';
y=r(2,3002:N)';
z=r(3,3002:N)';
clear r
figure(3),plot3(x,y,z),grid on
function [rdot] = f (t, r)
sigma = -0.38;
alpha = 5;
beta = -10;
x = r(1);
y = r(2);
z = r(3);
rdot = zeros(3,1);
rdot(1) = alpha * x - y * z;
rdot(2) = beta * y + x * z;
rdot(3) = sigma * z + (x * y) / 3;
end
8 comentarios
Numan
el 12 de Jul. de 2023
Numan
el 12 de Jul. de 2023
Here is my help to make you capable to help yourself:
Numan
el 12 de Jul. de 2023
Torsten
el 12 de Jul. de 2023
This is not a MATLAB question - thus not suited for this forum.
Numan
el 12 de Jul. de 2023
Numan
el 12 de Jul. de 2023
Categorías
Más información sobre App Building en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





