필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Problem with for-while loop, simple coding error?

조회 수: 1 (최근 30일)
Olle Haglund
Olle Haglund 2018년 11월 13일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi! I Have an assignment at school in which i am supposed to calculate the diameter of a shaft in order to not exceed the stress limit.
Basically i have devided the shaft in to 1000 segments and calculated bending moment, torsion and so on in each segment, so i have vectors describing those things.
Now I want to itterate over each segment to find a diameter that is big enough so it doesn't exceed the stress limit.
for i=1:1000
while ("my stess equation including the diameter, bending moment and so on") > stress limit
D(i)=D(i)+0.0001
end
end
The problem is that the D I get out of the loop is the same as the one I put in (the while loop is fulfilled without increasing the diameter). But when i calculate it without the loop i get values that are in fact larger than the stress limit. Therefore i guess there must be something wrong with my loop, but im not very good at matlab so... Any help is much apreciated!
  댓글 수: 4
Olle Haglund
Olle Haglund 2018년 11월 13일
I cant really give the exact code since my teacher is going to check it for plagiarism but the basic is:
a=[20 40 60 40 20];
D=[5 5 5 5 5]; %just a starting value
for i=1:5
while (a(i)/D(i))>2
D(i)=D(i)+1
end
end
Is the loop written correctly?
Adam
Adam 2018년 11월 13일
The loop you have given certainly changes the D values and terminates after having updated it numerous times.

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by