Trouble with Matrix Dimensions

1 回表示 (過去 30 日間)
Patrick
Patrick 2013 年 11 月 20 日
コメント済み: Patrick 2013 年 11 月 21 日
I am trying to simulate the kinematics of a crank slider in matlab. I have obtained a function which I believe to be correct, however matlab gives me this error:
>> velx = -r*sin(a) - L*(asin((r/L)*sin(a)))*(acos(((r/L)*sin(a))*((r/L)*sin(a))))
Error using *
Inner matrix dimensions must agree.
The variable 'a' is a 1x100 matrix generated via the linspace command. r and L are simply 1x1 single digit numbers. How can I get around this error? I want to plot the output of velx vs 'a' to obtain a graph.
It works if 'a' is just a 1x1 number, but doing it this way would require me to manually type in the values for 'a' 100 times and this would be tedious. I think perhaps there is a way to do it with a for loop command?
If anyone could help it would be much appreciated.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 20 日
編集済み: Azzi Abdelmalek 2013 年 11 月 20 日
Use operation element by element .*
velx = -r*sin(a) - L*(asin((r/L)*sin(a))).*(acos(((r/L)*sin(a)).*((r/L)*sin(a))))
  1 件のコメント
Patrick
Patrick 2013 年 11 月 21 日
Thanks man, you're a life saver

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by