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

 Réponse acceptée

Jan
Jan le 27 Mar 2021
Modifié(e) : Jan le 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 commentaires

Monica W
Monica W le 27 Mar 2021
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 le 27 Mar 2021
Modifié(e) : Jan le 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by