# I am getting error like invalid expression

조회 수: 9(최근 30일)
nune pratyusha 2022년 8월 26일
댓글: nune pratyusha 2022년 8월 26일
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.

댓글을 달려면 로그인하십시오.

### 답변(1개)

Karim 2022년 8월 26일
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표시숨기기 이전 댓글 수: 4
nune pratyusha 2022년 8월 26일
yes after modification i changed functiom name as run_L_p1 and saved it as run_L_p1

댓글을 달려면 로그인하십시오.

### 범주

Find more on Direction of Arrival Estimation in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by