size mismatch in matlab function block
4 views (last 30 days)
Show older comments
chuyen hoangcao
on 28 Oct 2020
Edited: Walter Roberson
on 29 Oct 2020
i dont know why there are some errors about size mismatch in my code, because as you can see, variable s has dimension is [1,2],Cl is [2,2] .Therefore i think the result will be [1,2] ,but it doesnt work.Please help me.
My code:
function [Cl,gl,ds] = fcn(q1,q2,dq2,dq1, Tl,Th,de,e,s,t)
%Matrices of dynamic equation.
a = 1.024;b = 0.24;Ro = 0.16;
g = 9.8;
Ml = [a+2*b*cos(q2) Ro+b*cos(q2); Ro+b*cos(q2) Ro];
Cl = [-2*b*sin(q2)*dq2 -b*sin(q2)*dq2; b*sin(q2)*dq1 0];
gl = [2.5*g*Ro*cos(q1+q2)+1.67*0.864*cos(q1) 2.5*g*Ro*cos(q1+q2)];
lamda = 0.6; ep = 3;d =1.2;
theta = [0.99; 0.12];
wl = 0.3+0.2*sin(2*t)+0.3*sin(20*t) - 0.2*sin(10*t)+ 0.3*sin(21*t);
w0 = 0.2 + 0.3*sin(15*t);
% dieu kien cua w estimation
if norm(s) > ep
Row = d*s./norm(s);
else
Row = d*s./ep;
end
we = w0 + Row;
% el(t) = -e(t);
Yl =( - de*Ml*lamda - e*Cl*lamda +gl);
ds =(-de*Ml*lamda -s*Cl - Yl*theta -(2*we-wl)+Tl+Th).*inv(Ml);
0 Comments
Accepted Answer
Fangjun Jiang
on 28 Oct 2020
Edited: Fangjun Jiang
on 28 Oct 2020
[1 2]*[2 2; 2 2] is correct.
[1 2].*[2 2; 2 2] is wrong (without implicit expansion)
3 Comments
Fangjun Jiang
on 28 Oct 2020
take a particular set of values for all the input arguments, run the code line by line, stop at the line where the error occured, run indivudual section of that line of code if necessary, you will find where and what caused the error.
More Answers (0)
See Also
Categories
Find more on General Applications in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!