Subscripted assignment dimension mismatch.

When I changed the value of C from [0 1] to eye(2) I am getting the following error:
Subscripted assignment dimension mismatch.
Error in set_quasi (line 46)
Phi( (i-1)*nu+1:i*nu, (i-1)*nx+1:i*nx) = Ctid
Please help me to resolve this.
I have attached my code also.
clc
clear
% define model parametres
Kp=3.3; Ao1=0.1781; Ao2=0.1781; At1=15.5179;At2=15.5179; g=981;Le1=15; Le2=15;
Ac=[(-Ao1*sqrt(g/(2*Le1))/At1) 0;(Ao1*sqrt(g/(2*Le2))/At2) (-Ao2*sqrt(g/(2*Le2))/At2)];
Bc=[Kp/At1;0];
Cc=[0 1];
%discrete time model
dt=0.01; %sampling time
sys=ss(Ac,Bc,Cc,0);
ds=c2d(sys,dt);
Ad=ds.a; Bd=ds.b; Cd= ds.c;
N = 9;
u_max = 18;
u_min = 2;
Atid=[Ad zeros(2,1);eye(1) zeros(1,2)];
Btid=[Bd;zeros(1)];
Ctid=[Cd zeros(1)];
% Number of states and control signals
nx = size(Atid,2);
nu = size(Btid,2);
% LQR values
Q_mat =[Ctid'*Ctid];
S = eye(nu);
R = 0.00001;
[~,P,~] = dlqr(Atid,Btid,Q_mat,R);
%% Reference Parameters
% Initilize matrices
% xf = zeros(1:nx)';
xf = [15 15 0]';
% Initilize QP matrices
Psi = zeros(nx*N, nx);
Omega = zeros(nx*N, nu*N);
Phi = zeros(nu*N, nx*N);
H11 = zeros(nu*N,nu*N);
H22 = zeros(nx*N,nx*N);
H33 = zeros(nu*N,nu*N);
H44 = [zeros(nx,nx*(N-1)) eye(nx)];
% Construct QP matrices
for i = 1:N
Psi( (i-1)*nx+1:i*nx, :) = Atid^i;
Phi( (i-1)*nu+1:i*nu, (i-1)*nx+1:i*nx) = Ctid
H11( (i-1)*nu+1:i*nu, (i-1)*nu+1:i*nu) = R;
if i<N
H22( (i-1)*nx+1:i*nx, (i-1)*nx+1:i*nx ) = Q_mat;
H33( (i-1)*nu+1:i*nu, (i-1)*nu+1:i*nu ) = S;
else
H22( (i-1)*nx+1:i*nx, (i-1)*nx+1:i*nx ) = P;
end
for j=1:i
Omega( (i-1)*nx+1:i*nx, (j-1)*nu+1:j*nu ) =[Atid^(i-j)*Btid] ;
end
end

4 Commenti

Torsten
Torsten il 26 Mag 2022
Modificato: Torsten il 26 Mag 2022
size(Ctid) must equal (nu,nx).
If this is not the case, the assignment
Phi( (i-1)*nu+1:i*nu, (i-1)*nx+1:i*nx) = Ctid
will fail.
By the way: In the code that produced the error message, you assign
Phi( (i-1)*nu+1:i*nu, (i-1)*nx+1:i*nx+1) = Ctid
which is different from what you wrote in the code you posted.
Here, size(Ctid) must equal (nu,nx+1)
Check it.
I edited my question as you suggested. If I changed the dimension of Ctid to (2 x3) than how I am going to assign its value to Phi. I know that I have to make changes in dimension of every variable but I am unable to do it. Please help.
Thanks for the help .I resolved the issue.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Prodotti

Release

R2017a

Tag

Richiesto:

il 26 Mag 2022

Commentato:

il 27 Mag 2022

Community Treasure Hunt

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

Start Hunting!

Translated by