Array row is not added in for loop

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

 Risposta accettata

Jan
Jan il 27 Mar 2021
Modificato: Jan il 27 Mar 2021
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 Commenti

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 il 27 Mar 2021
Modificato: Jan il 27 Mar 2021
You are welcome. Maybe this question shows you, that many programming problems can be solved without writing some code. This is a valuable lesson.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Mathematics in Centro assistenza e File Exchange

Tag

Richiesto:

il 27 Mar 2021

Modificato:

Jan
il 27 Mar 2021

Community Treasure Hunt

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

Start Hunting!

Translated by