Effacer les filtres
Effacer les filtres

I am getting error like invalid expression

2 vues (au cours des 30 derniers jours)
nune pratyusha
nune pratyusha le 26 Août 2022
Commenté : nune pratyusha le 26 Août 2022
function Le=lyapunovk(n,rhs_ext_fcn,tstart,stept,tend,ystart,R);
n1=n; n2=n1*(n1+1);
% Number of steps
nit = round((tend-tstart)/stept);
% Memory allocation
y=zeros(n2,1); cum=zeros(n1,1); y0=y;
gsc=cum; znorm=cum;
% Initial values
y(1:n)=ystart(:);
for i=1:n1
y((n1+1)*i)=1.0; end;
t=tstart;
% Main loop
for ITERLYAP=1:nit
% Solutuion of extended ODE system
[T,Y] = ode15s(rhs_ext_fcn,[t t+stept],y,R);
Y=transpose(Y);
t=t+stept;
y=Y(size(Y,1),:);
for i=1:n1
for j=1:n1
y0(n1*i+j)=y(n1*j+i); end;
end;
%
% construct new orthonormal basis by gram-schmidt
%
znorm(1)=0.0;
for j=1:n1
znorm(1)=znorm(1)+y0(n1*j+1)^2; end;
znorm(1)=sqrt(znorm(1));
for j=1:n1
y0(n1*j+1)=y0(n1*j+1)/znorm(1); end;
for j=2:n1
for k=1:(j-1)
gsc(k)=0.0;
for l=1:n1
gsc(k)=gsc(k)+y0(n1*l+j)*y0(n1*l+k); end;
end;
for k=1:n1
for l=1:(j-1)
y0(n1*k+j)=y0(n1*k+j)-gsc(l)*y0(n1*k+l);
end;
end;
znorm(j)=0.0;
for k=1:n1
znorm(j)=znorm(j)+y0(n1*k+j)^2; end;
znorm(j)=sqrt(znorm(j));
for k=1:n1
y0(n1*k+j)=y0(n1*k+j)/znorm(j); end;
end;
%
% update running vector magnitudes
%
for k=1:n1
cum(k)=cum(k)+log(znorm(k)); end;
%
% normalize exponent
%
for k=1:n1
lp(k)=cum(k)/(t-tstart);
end;
% Output modification
i=1;
while i<=n1
j=1;
while j<=n1;
y(n1*j+i)=y0(n1*i+j);
j=j+1;
end
i=i+1;
end;
y=transpose(y);
nit=nit+1;
end
function f=l_ext(t,x,R)
SIGMA = 10;
BETA = 8/3;
f=zeros(9,1);
X= [x(4) x(7) x(10);
x(5) x(8) x(11);
x(6) x(9) x(12)];
%Lorenz equation
f(1)=SIGMA*(x(2)-x(1));
f(2)=-x(1).*x(3)+R*x(1)-x(2);
f(3)=x(1).*x(2)-BETA*x(3);
%Linearized system
Jac=[-SIGMA, SIGMA, 0;
R-x(3), -1, -x(1);
X(2), x(1), -BETA];
%Variational equation
f(4:12)=Jac*X;
%Output data must be a column
function run_L_p(n,rhs_ext_fcn,0,0.5,200,[0 1 0],10,R_min,R_max,nk);
hold on;
rhs_ext_fcn=@l_ext
n=3;
nk=100;
R_min=10;
R_max=28;
R_step=(R_max-R_min)/nk
R=R_min;
while R<=R_max
lp=lyapunovk(3,@l_ext,0,0.5,200,[0 1 0],10,R);
R=R+R_step;
plot(R,lp);
end
I am gettion error:
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

Réponses (1)

Karim
Karim le 26 Août 2022
the error is located in syntax of the run_L_p function. You need to change the numeric values into variables
i.e. change
function run_L_p(n,rhs_ext_fcn,0,0.5,200,[0 1 0],10,R_min,R_max,nk)
into
function run_L_p(n,rhs_ext_fcn,var1,var2,var3,var4,var5,R_min,R_max,nk)
before call the function you need to define the extra variables as
var1 = 0;
var2 = 0.5;
var3 = 200;
var4 = [0 1 0];
var5 = 10;
or if they are fixed you can set them in the function itself.
  5 commentaires
Bruno Luong
Bruno Luong le 26 Août 2022
Sometime it's good to read what is displayed on your PC monitor:
"Error in run_L_p1 (line 16)
lp=lyapunovk(3,@l_ext,0,0.5,200,[0 1 0],10,R)"
nune pratyusha
nune pratyusha le 26 Août 2022
yes after modification i changed functiom name as run_L_p1 and saved it as run_L_p1

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by