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