Error using ./ Matrix dimensions must agree.

Hi, I have this equation entered:
y=tan(r)*x-(g.*x.^2./(2*vo^2*(cos(r)).^2))+yo;
vo,g,and yo are all constant scalars.
x is a column vector with 17 entries
r is a row vector with 5 entries
When attempting to run the code I keep getting Matrix dimensions error. I want to make it so that each value of r multiplies with every value of x. Such that I will get a matrix with the values of y, with each value of r with varying x.
Any help would be greatly appreciated. Thanks.

 採用された回答

Steven Lord
Steven Lord 2016 年 9 月 29 日

2 投票

If you're using release R2016b you can take advantage of implicit expansion. You need to make one minor modification by replacing the first * operator (between tan(r) and x) with the .* operator.

その他の回答 (1 件)

Massimo Zanetti
Massimo Zanetti 2016 年 9 月 29 日

3 投票

To achieve what you want, you have to generate all possible copules of values from x and r (no matter their sizes). Given your vectors x,r, implement this:
x=x(:); r=r(:);
[R,X] = meshgrid(r,x);
Y = tan(R).*X-g*X.^2./(2*vo^2*cos(R).^2)+yo;
Then, Y will be your matrix.

タグ

質問済み:

J
J
2016 年 9 月 29 日

コメント済み:

2016 年 9 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by