How do I use single precision numbers in a summation? My result is not coming out as expected.

So this is the question I havve. However, when I change all the numeric values to single precision, it does not make a difference in the output. Any idea what I am doing wrong?
any suggestions would be appreciated!

 採用された回答

Walter Roberson
Walter Roberson 2023 年 9 月 25 日
You are not doing repeated addition. Repeated addition is not the same as multiplication.
Also, a and b are scalar, so a*b is a scalar, and there is no point in sum() of a scalar.
Hint: see repelem and repmat

4 件のコメント

Elaina
Elaina 2023 年 9 月 25 日
ok, see I thought the sum thing was not correct, I was not sure how it should be done and someone else said to do it that way.
Elaina
Elaina 2023 年 9 月 25 日
It is expecting sum to be used, though. It expects a scalar result.
Another hint:
P*ones(1,Q)
is one way to construct a vector of size 1 x Q that contains all P
Elaina
Elaina 2023 年 9 月 25 日
Ok, I had tried creating am array earlier but I obviously did not do it correctly. I used repmat and that fixed it. Thank you!

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

その他の回答 (0 件)

カテゴリ

製品

リリース

R2023a

質問済み:

2023 年 9 月 25 日

コメント済み:

2023 年 9 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by