急求助matlab中的一个问题!!!各路大神帮帮忙啊!!小弟感激不尽!!
A=[0,1,0,0;0,0,0,0;0,0,0,1;0,0,37.22,0]B=[0;1;0;0.84]C=[1,0,0,0;0,0,1,0]D=[0;0]Q=[1,0...
A=[0,1,0,0; 0,0,0,0; 0,0,0,1; 0,0,37.22,0]
B=[0; 1; 0; 0.84]
C=[1,0,0,0; 0,0,1,0]
D=[0; 0]
Q=[1,0,0,0; 0,0,0,0; 0,0,1,0; 0,0,0,0]
R=1
K=lqr(A,B,Q,R)
M 文件(1)
function[Nbar]=rscale(A,B,C,D,K)
% given the single-input linear system
% x=Ax+Bu
% y=Cx+Du
% and the feedback matrix K
% the function rscale(A,B,C,D,K)finds the scale factor N which will
% eliminate the steady-state error to a step reference
s=size(A,1)
Z=[zeros([1,s]) 1]
N=inv([A,B;C,D])*Z'
Nx =N(1:s)
Nu=N(1+s)
Nbar=Nu+K*Nx
M 文件(2)
A=[0,1,0,0; 0,0,0,0; 0,0,0,1; 0,0,37.22,0]
B=[0; 1; 0; 0.84]
C=[1,0,0,0; 0,0,1,0]
D=[0; 0]
Q=[1,0,0,0; 0,0,0,0; 0,0,1,0; 0,0,0,0]
R=1
K=lqr(A,B,Q,R)
Ac=[(A-B*K)];Bc=[B];Cc=[C];Dc=[D]
T=0:0.02:10
U=3.14159*ones(size(T))
Cn=[1,0,0,0]
Nbar=rscale(A,B,Cn,0,K)
Bcn=[Nbar*B]
[Y,X]=lsim(Ac,Bcn,Cc,Dc,U,T)
plot(T,X(:,1),'--');hold on
plot(T,Y(:,2));hold on
plot(T,Y)
legend('Pendulum','Link')
我保存的文件名是rscale.m(和函数名一样)
我在命令窗口中输入rscale 但是却提示
Error: File: rscale.m Line: 14 Column: 1
Function definitions are not permitted in this context.
请问各位大神,为什么会出现这种情况呢,该如 展开
B=[0; 1; 0; 0.84]
C=[1,0,0,0; 0,0,1,0]
D=[0; 0]
Q=[1,0,0,0; 0,0,0,0; 0,0,1,0; 0,0,0,0]
R=1
K=lqr(A,B,Q,R)
M 文件(1)
function[Nbar]=rscale(A,B,C,D,K)
% given the single-input linear system
% x=Ax+Bu
% y=Cx+Du
% and the feedback matrix K
% the function rscale(A,B,C,D,K)finds the scale factor N which will
% eliminate the steady-state error to a step reference
s=size(A,1)
Z=[zeros([1,s]) 1]
N=inv([A,B;C,D])*Z'
Nx =N(1:s)
Nu=N(1+s)
Nbar=Nu+K*Nx
M 文件(2)
A=[0,1,0,0; 0,0,0,0; 0,0,0,1; 0,0,37.22,0]
B=[0; 1; 0; 0.84]
C=[1,0,0,0; 0,0,1,0]
D=[0; 0]
Q=[1,0,0,0; 0,0,0,0; 0,0,1,0; 0,0,0,0]
R=1
K=lqr(A,B,Q,R)
Ac=[(A-B*K)];Bc=[B];Cc=[C];Dc=[D]
T=0:0.02:10
U=3.14159*ones(size(T))
Cn=[1,0,0,0]
Nbar=rscale(A,B,Cn,0,K)
Bcn=[Nbar*B]
[Y,X]=lsim(Ac,Bcn,Cc,Dc,U,T)
plot(T,X(:,1),'--');hold on
plot(T,Y(:,2));hold on
plot(T,Y)
legend('Pendulum','Link')
我保存的文件名是rscale.m(和函数名一样)
我在命令窗口中输入rscale 但是却提示
Error: File: rscale.m Line: 14 Column: 1
Function definitions are not permitted in this context.
请问各位大神,为什么会出现这种情况呢,该如 展开
1个回答
推荐于2017-12-16
展开全部
应该先把函数部分的内容保存成:
function[Nbar]=rscale(A,B,C,D,K)
% given the single-input linear system
% x=Ax+Bu
% y=Cx+Du
% and the feedback matrix K
% the function rscale(A,B,C,D,K)finds the scale factor N which will
% eliminate the steady-state error to a step reference
s=size(A,1)
Z=[zeros([1,s]) 1]
N=inv([A,B;C,D])*Z'
Nx =N(1:s)
Nu=N(1+s)
Nbar=Nu+K*Nx
再把余下的内容保存成另一个M文件(文件名任意,但应该是一个合法的M文件名,后面运行的是这个文件):
A=[0,1,0,0; 0,0,0,0; 0,0,0,1; 0,0,37.22,0]
B=[0; 1; 0; 0.84]
C=[1,0,0,0; 0,0,1,0]
D=[0; 0]
Q=[1,0,0,0; 0,0,0,0; 0,0,1,0; 0,0,0,0]
R=1
K=lqr(A,B,Q,R)
Ac=[(A-B*K)];Bc=[B];Cc=[C];Dc=[D]
T=0:0.02:10
U=3.14159*ones(size(T))
Cn=[1,0,0,0]
Nbar=rscale(A,B,Cn,0,K)
Bcn=[Nbar*B]
[Y,X]=lsim(Ac,Bcn,Cc,Dc,U,T)
plot(T,X(:,1),'--');hold on
plot(T,Y(:,2));hold on
plot(T,Y)
legend('Pendulum','Link')
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询