Info

此问题已关闭。 请重新打开它进行编辑或回答。

help with for loop

1 次查看(过去 30 天)
Seif Kazamel
Seif Kazamel 2018-11-23
关闭: MATLAB Answer Bot 2021-8-20
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 个评论
Seif Kazamel
Seif Kazamel 2018-11-23
Error in Analytical (line 14)
D = Di;
i changed it to i= 1:10
it gave me the error above
Walter Roberson
Walter Roberson 2018-11-24
you have not defined Di at that point

回答(1 个)

Daniel Vela
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

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by