size mismatch in matlab function block

3 ビュー (過去 30 日間)
chuyen hoangcao
chuyen hoangcao 2020 年 10 月 28 日
編集済み: Walter Roberson 2020 年 10 月 29 日
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);

採用された回答

Fangjun Jiang
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
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.
chuyen hoangcao
chuyen hoangcao 2020 年 10 月 29 日
it ran when i delete '.' in front of inv 'Ml'.Thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeneral Applications についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by