Why do I keep getting matrix dimensions must agree?

I keep getting this error and I can't figure out why. Here's my code
g= 9.81
v0=[5,10,15,20];
theta= [0, .17453293, .52359878, .78539816, 1.04719755,1.57079633];
tf=2*v0.*sin(theta)/g;
t=0:0.01:tf; hold all x=v0.*(theta).*t;
y=v0*sin(theta)*t-g*t.^2/2;
hold on plot(x,y)
Matrix dimensions must agree.
Error in BallTrajectory (line 7) tf=2*v0.*sin(theta)/g;

 採用された回答

James Tursa
James Tursa 2018 年 7 月 10 日
編集済み: James Tursa 2018 年 7 月 10 日

0 投票

>> size(v0)
ans =
1 4
>> size(theta)
ans =
1 6
So it is complaining about the v0 .* sin(theta) operation

3 件のコメント

Taylor Gates
Taylor Gates 2018 年 7 月 10 日
Okay I changed them both to be the same size and I now get this. g= 9.81
v0=[5,10,15,20,25,30];
theta= [6, .17453293, .52359878, .78539816, 1.04719755, 1.57079633];
tf=2.*v0.*sin(theta)/g;
t=0:0.01:tf; hold all x=v0.*(theta).*t
y=v0.*sin(theta)*t-g*t.^2/2;
hold on
Error using .* Matrix dimensions must agree.
Error in BallTrajectory (line 11) x=v0.*(theta).*t
James Tursa
James Tursa 2018 年 7 月 10 日
tf is a vector. What are you expecting to get with the t=0:0.01:tf ?
What is your ultimate goal here? To produce multiple plots with different values of tf?
Taylor Gates
Taylor Gates 2018 年 7 月 10 日
Yes that’s the goal. Doing multiple plots with different inputs for initial velocity and launch angle.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by