help with for loop
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hello everyone,
I got these two equation. They represent the depth.
The first one is the first depth measured which represents the first value of (Di-1) in the generalized equation below.
I need the code to generate Di until it reaches the condition.
I typed this code buti don't know if it is right as it doesn't fit the calculations i make myself.
Thanks.


% This script represents the Analytical gas lift design
Pks = input('Enter surface Kick off pressure');
dPkm = input('Enter kick off pressure margin');
Phf = input('Enter Wellhead Pressure');
Gs = input('Enter Static Gradient') ;
Pcs = input('Enter surface casing pressure');
dPcm = input('Enter casing pressure margin');
Phfd = input('Enter Wellhead desired Pressure');
Gfd = input('Enter desired flowing Gradient') ;
D = (Pks - dPkm - Phf)/(Gs-(Pks - dPkm)/40000);
D=Di;
for Di=1:10
Di = (Pcs - dPcm - Phfd+(Gs-Gfd)*Di)/(Gs-(Pcs - dPcm)/40000);
if Di > 5000;
break
end
end
댓글 수: 3
Walter Roberson
2018년 11월 23일
no you use Di as the for loop variable but you also compute it in the loop . you should use different variables
Seif Kazamel
2018년 11월 23일
Walter Roberson
2018년 11월 24일
you have not defined Di at that point
답변 (1개)
Daniel Vela
2018년 11월 24일
Hello, please take a look at this code, it might help you fix what you need. Be aware that it might be wise to use a while loop if you want the program to calculate your value more than a determined number of times until it reaches your condition.
userinput1=input('enter value 1');
userinput2=input('enter value 2');
aMinusOne=userinput1+userinput2 %I define my starting value for a(i-1) through formula (use your formula here)
for i=1:10 % The loop will calculate a 10 times and then exit if condition is not.
a=aMinusOne+5; % the formula takes a(i-1) to calculate the current value of a
if a>150 %if condition is met, the loop ends and prints some nice message.
'the condition was reached'
break
end
aMinusOne=a;% we redifine A(i-1) with the most recently calculated value for A for next iteration.
end
댓글 수: 0
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!