I'm trying to add a new row whenever L*W*H = 50, but when I run it the array dimensiones does not change. What's going on...?
syms L W H;
dimensiones = [0, 0, 0];
for W = 1:100
L = W*3;
for H = 1:100
if L*W*H==50
dimensiones = [dimensiones; L, W, H];
end
end
end

 採用された回答

Jan
Jan 2021 年 3 月 27 日
編集済み: Jan 2021 年 3 月 27 日

1 投票

What is the purpose of
syms L W H;
Why do you want to solve this symbolically? As soon as you omit this line, the code works fine. But let me mention, that there is no value, for which W * 3 * H equals 50. This easy to prove, because 50 is not a multiple of 3. If you use 51, which is 3 * 17, a row is added.

2 件のコメント

Monica W
Monica W 2021 年 3 月 27 日
Oh, that was silly of me...! I'm not sure what I was trying to do there with the symbolic variables.
I understand re: the 50 problem. It's what an exercise is asking me to do, but I guess it's either a trick question or poorly formulated...
Thanks Jan!
Jan
Jan 2021 年 3 月 27 日
編集済み: Jan 2021 年 3 月 27 日
You are welcome. Maybe this question shows you, that many programming problems can be solved without writing some code. This is a valuable lesson.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Mathematics についてさらに検索

タグ

質問済み:

2021 年 3 月 27 日

編集済み:

Jan
2021 年 3 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by