How to divide a vector by a constant?

1 回表示 (過去 30 日間)
Lance Shallenberger
Lance Shallenberger 2021 年 9 月 16 日
c=3*10^8
c = 300000000
speeds=(.1*c:.9*c/8:.9*c)
speeds = 1×8
30000000 63750000 97500000 131250000 165000000 198750000 232500000 266250000
y=1/sqrt(1-(speeds.^2./c^2))
Error using /
Matrix dimensions must agree.
What is my error?

採用された回答

Image Analyst
Image Analyst 2021 年 9 月 16 日
The denominator with sqrt() is a vector so you need a dot before the slash
y = 1 ./ sqrt(1 - (speeds .^ 2 ./ c ^ 2))
  1 件のコメント
Lance Shallenberger
Lance Shallenberger 2021 年 9 月 16 日
thanks!

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

その他の回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 9 月 16 日
You need to use elementwise division everywhere in your equation for y
c=3*10^8;
speeds=(.1*c:.9*c/8:.9*c);
% v
y=1./sqrt(1-(speeds.^2./c^2))
y = 1×8
1.0050 1.0234 1.0574 1.1121 1.1974 1.3350 1.5824 2.1701
  1 件のコメント
Lance Shallenberger
Lance Shallenberger 2021 年 9 月 16 日
thank you!

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

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by