lorentz simulation error what is the error please help

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 commentaires

Works for me (see above).
Numan
Numan le 12 Juil 2023
Modifié(e) : Numan le 12 Juil 2023
thanks a lot for clearing this out.Im actually simulating the chen system with its chen attractor using same principle but im getting error
the parameters and equations for the chen system is dx/dt = alpha * x - y * z;
dy/dt = beta * y + x * z;
dz/dt = sigma * z + (x * y) / 3;
with sigma=-0.38 beta=-10 and ALPHA =5
many thanks to you
my code for chen system is
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 = 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;
rdot=zeros(3,1);
rdot(1) = alpha * x - y * z;
rdot(2) = beta * y + x * z;
rdot(3) = sigma * z + (x * y) / 3;
end
im getting this error Unrecognized function or variable 'x'.
Error in untitled8>f (line 34)
rdot(1) = alpha*x-y*z;
Error in untitled8 (line 15)
k1 = dt * f( t(i) , r(:,i) );
Sam Chak
Sam Chak le 12 Juil 2023
Modifié(e) : Sam Chak le 12 Juil 2023
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

Connectez-vous pour commenter.

Réponses (1)

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 commentaires

woow many thanks i got it too..can you please tell me how to edit my code so as my 3D plot axes are of 3 different colour please
After i hav ecompleted the simulation of chen system i will need to compute the fractal dimension also which i have no cllue..ay help please
Torsten
Torsten le 12 Juil 2023
Modifié(e) : Torsten le 12 Juil 2023
Here is my help to make you capable to help yourself:
THANKS ALOT Torsten.i will defo give it a try Have you got any idea how to compute its capacity dimension please for chen systen i would be gratfeful
This is not a MATLAB question - thus not suited for this forum.
I mean computing the fractal dimension using box to box method is not matlab?
Torsten
Torsten le 12 Juil 2023
Modifié(e) : Torsten le 12 Juil 2023
No. But if you have MATLAB code for this method and it shows errors for the above system, we can try to help you. That's why I suggested to pass the free MATLAB online tutorial.
% Compute Fractal Dimension (Capacity Dimension)
epsilon = 0.1:0.1:10; % Range of epsilon values
N_eps = length(epsilon); % Number of epsilon values
N_points = zeros(N_eps, 1); % Number of points within epsilon distance
for i = 1:N_eps
for j = 1:length(x)
dist = sqrt((x - x(j)).^2 + (y - y(j)).^2 + (z - z(j)).^2);
N_points(i) = N_points(i) + sum(dist < epsilon(i));
end
end
% Compute the capacity dimension
log_N = log(N_points);
log_eps = log(epsilon);
coeffs = polyfit(log_eps, log_N, 1);
fractal_dim = coeffs(1);
disp("Fractal Dimension (Capacity Dimension): " + fractal_dim);
oh sorry i have my code for capacity dimension for my chen system but it wont work unfortunately..thank you a lot

Connectez-vous pour commenter.

Catégories

En savoir plus sur App Building dans Centre d'aide et File Exchange

Question posée :

le 12 Juil 2023

Commenté :

le 12 Juil 2023

Community Treasure Hunt

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

Start Hunting!

Translated by