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

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

what is the error you get?
try to attach a sample (image), for better illustration.
it only plot one point not all loop points
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

I'd like to know how get output as vector in for loop in general
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개)

카테고리

도움말 센터File 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