In an assignment A(I) = B, the number of elements in B and I must be the same
Ältere Kommentare anzeigen
Hi everyone, Here is the code, that gives me the error that I put in my title. Please correct my code, Also, I am new in MATLAB, please advice me Thanks in advance. When i was created it, its working nicely, but, after one day i faced the above problem. my initial values are; y0=[q1 q2 q3 q4 w1 w2 w3]=[0 0 0 1 0 0 0]; t=0:0.3:50; i used ode45 to solve the following problem. Error coming from 18th line. Please fix the following problem
function xdot=controller1(t,y)
global u1 u2 u3 ue1 ue2 ue3 Ix Iy Iz q1c q2c q3c q4c Kv Kp
dy=zeros(7,1); % a column vector
% External torque
ue1=0;
ue2=0;
ue3=0;
Kv=370;
Kp=315;
% Quaternions
dy(1)=((y(7)*y(2)-y(6)*y(3)+y(5)*y(4))*.5);
dy(2)=((-y(7)*y(1)+y(5)*y(3)+y(6)*y(4))*.5);
dy(3)=((y(6)*y(1)-y(5)*y(2)+y(7)*y(4))*.5);
dy(4)=((-y(5)*y(1)-y(6)*y(2)+y(7)*y(3))*.5);
%Omegas
dy(5)=(u1+ue1+(Iy-Iz)*y(6)*y(7))/Ix;
dy(6)=(u2+ue2+(Iz-Ix)*y(7)*y(5))/Iy;
dy(7)=(u3+ue3+(Ix-Iy)*y(5)*y(6))/Iz;
% Error Quaternion
qe1=(q4c*y(1)+q3c*y(2)-q2c*y(3)-q1c*y(4));
qe2=(-q3c*y(1)+q4c*y(2)-q1c*y(3)-q2c*y(4));
qe3=(q2c*y(1)-q1c*y(2)+q4c*y(3)-q3c*y(4));
% Control torque
u1=-Kp*qe1-Kv*y(5);
u2=-Kp*qe2-Kv*y(6);
u3=-Kp*qe3-Kv*y(7);
xdot=[dy(1);dy(2);dy(3);dy(4);dy(5);dy(6);dy(7)];
end
5 Kommentare
Dipak giri
am 22 Dez. 2011
C.J. Harris
am 22 Dez. 2011
Without further information it is difficult to answer this question. You have a dimension mismatch, but since you are using so many global variables we have no idea of their size.
Dipak giri
am 22 Dez. 2011
C.J. Harris
am 22 Dez. 2011
Then debug your program and make sure the following variables also are of the intended size (single values probably):
u1 u2 u3 Ix Iy Iz
Also, why are you setting ue1, ue2, ue3, Kv and Kp as global variables, as they dont change between iterations?
Dipak giri
am 22 Dez. 2011
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Coordinate Transformations finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!