How to plot a 2D graph using all the for loop values؟

조회 수: 1 (최근 30일)
Mostafa Shehab
Mostafa Shehab 2015년 7월 31일
댓글: Walter Roberson 2015년 8월 2일
clc,clear
xi=input('The solution gas-oil ratio(Rsb)\n');
yi=input( ' The specific gravity of separator gas\n');
Ti=input('reservoir temperature\n');
pi=input('reservoire pressure\n');
zi=input('API of stock tank\n');
Xi=(.013098*Ti^.282372)-(8.2*10^-6*zi^2.176124);
pb=1091.47*(xi^.081465*yi^-.161488*10^Xi-.740152)^5.35489;
fprintf('%s\n%d\n','pb',pb);
fprintf('%4s%15s%20s\n','pi','Co','D');
for ni=1000:1000:10000
n=0;
pi=n+ni;
if pi>=pb
RS=xi;
Co=(-1433+5*xi+2.902*Ti+1.327*yi+12.61*zi)/(10^5*pi);
Apo=52.8-0.01*xi;
for ki=1:100
Aa=-49.893+85.0149*yi-3.70373*yi*Apo+.0479*yi*Apo^2+2.98914*Apo-0.035688*Apo^2;
bpo=(xi*yi+4600*zi)/(73.71+(xi*yi/Aa));
end
Ci=bpo+(.167+16.181*(10^(-0.0425*bpo)))*(pi/1000)-.01*(.299+263*(10^(-0.0603*bpo)))*(pi/1000)^2;
zai=Ci-(0.00302+1.505*Ci^-.951)*(Ti-60)^.938+(.0233*(10^-0.0161*Ci))*(Ti-60)^.475;
fprintf('%4d %15d%20d\n',pi,Co,zai);
end
end
plot(p,Co);
  댓글 수: 3
Mostafa Shehab
Mostafa Shehab 2015년 8월 2일
it only plot one point not all loop points
Walter Roberson
Walter Roberson 2015년 8월 2일
A sample of what you would like the plot to look like would be useful. But you can fix the problem about only plotting one point by making the change I showed in my Answer.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2015년 8월 1일
nvals = 1000:1000:10000;
for nidx = 1 : length(nvals)
n = nvals(nidx);
......
Co(nidx) = (-1433+5*xi+2.902*Ti+1.327*yi+12.61*zi)/(10^5*pi);
...
end
By the way, it is quite confusing for readers when you use "pi" as a variable instead of leaving it as the default constant 3.1415926 (etc)
  댓글 수: 2
Mostafa Shehab
Mostafa Shehab 2015년 8월 2일
I'd like to know how get output as vector in for loop in general
Walter Roberson
Walter Roberson 2015년 8월 2일
Follow the framework I gave here: create a vector of the input values, loop over the possible indices of the vector, pull out a particular input value from the vector by its index, store the output indexed by your counter.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactions, Camera Views, and Lighting에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by