size mismatch in matlab function block
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Fangjun Jiang
2020-10-28
编辑:Fangjun Jiang
2020-10-28
[1 2]*[2 2; 2 2] is correct.
[1 2].*[2 2; 2 2] is wrong (without implicit expansion)
3 个评论
Fangjun Jiang
2020-10-28
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!