Wiered Matlab Matrix Multiplication

t = linspace(0, 1, 100);
theta1 = linspace(0, 90, 100);
theta2 = linspace(0, 180, 100);
dtheta1 = t;
dtheta2 = 2*t;
ddtheta1 = 1;
ddtheta2 = 2;
T1 = zeros(100,1);
T2 = zeros(100,1);
m_1 = 10;
m_2 = 20;
l_1 = 5;
l_2 = 5;
g = 9.81;
for i = 1:100
M = [m_2*l_2^2 + 2*m_2*l_1*l_2*cos(theta2(i)) + (m_1 + m_2)*l_1^2, m_2*l_2^2 + m_2*l_1*l_2*cos(theta2(i));
m_2*l_2^2 + m_2*l_1*l_2*cos(theta2(i)), m_2*l_2^2 ];
% invM = inv(M);
G = [m_2*l_2*g*cos(theta1(i) + theta2(i)) + (m_1 + m_2)*l_1*g*cos(theta1(i)); m_2*l_2*g*cos(theta1(i) + theta2(i))];
C = [-m_2*l_1*l_2*sin(theta2(i))*dtheta1(i)^2 - 2*m_2*l_1*l_2*sin(theta2(i))*dtheta1(i)*dtheta2(i); m_2*l_1*l_2*sin(theta2(i))*dtheta1(i)^2];
M*[ddtheta1; ddtheta2] + C + G
end
I don't know why the last statement sometimes prints 2*1 but sometimes give something like this:
ans =
1.0e+03 *
5.2709
2.9356
Any suggestion where is this e terms coming from?
FYI: M is 2*2, G = 2*1, C = 2*1 matrices;

2 件のコメント

Roger Stafford
Roger Stafford 2017 年 11 月 19 日
The variables theta1 and theta2 are clearly meant to be in degrees, but you are using them as arguments for Matlab's 'cos' and 'sin' functions, which are intended to receive arguments in radians. That will give you a serious computation error.
Sonu Patidar
Sonu Patidar 2017 年 11 月 19 日
Yes, thanks for pointing out that.

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

回答 (1 件)

KL
KL 2017 年 11 月 19 日

0 投票

it is coming from
M*[ddtheta1; ddtheta2] + C + G
if you do not put a semicolon on matlab, you'll see the output of that line on command window.

4 件のコメント

Sonu Patidar
Sonu Patidar 2017 年 11 月 19 日
No, I was asking where that extra term 1.0e+03 * coming from? Anyway I got it. We need to convert floating point representation to uint64.
KL
KL 2017 年 11 月 19 日
e stands for exponent
John D'Errico
John D'Errico 2017 年 11 月 19 日
Exponential notation.
Sonu Patidar
Sonu Patidar 2017 年 11 月 19 日
Yes, you are right.

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

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2017 年 11 月 19 日

コメント済み:

2017 年 11 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by