Error in for loop calculation

1 Ansicht (letzte 30 Tage)
Avinav Kumar
Avinav Kumar am 30 Mär. 2021
Bearbeitet: Stephen23 am 30 Mär. 2021
Hi, I am getting 0 as answer though the answers cannot be zero. If some one can guide
temperature = 212 ; % temperature in deg F
oilapi = 41 ; % oil API
gamma = (0.00091 * temperature) - (0.0125*oilapi);
gasg = 0.65 ;
U(100)= 100;
for P = 101:2000
U(P) = gasg * U(P-1); %/ (18 * (10 ^ (gamma)))^1.205);
end
U

Akzeptierte Antwort

Stephen23
Stephen23 am 30 Mär. 2021
Bearbeitet: Stephen23 am 30 Mär. 2021
You are confusing data with indices. Do not use data as indices.
temperature = 212 ; % temperature in deg F
oilapi = 41 ; % oil API
gamma = (0.00091 * temperature) - (0.0125*oilapi);
gasg = 0.65 ;
P = 100:2000; % data!
U = P; % data!
for k = 2:numel(U) % indices!
U(k) = gasg * U(k-1); %/ (18 * (10 ^ (gamma)))^1.205);
end
U
U = 1×1901
100.0000 65.0000 42.2500 27.4625 17.8506 11.6029 7.5419 4.9022 3.1864 2.0712 1.3463 0.8751 0.5688 0.3697 0.2403 0.1562 0.1015 0.0660 0.0429 0.0279 0.0181 0.0118 0.0077 0.0050 0.0032 0.0021 0.0014 0.0009 0.0006 0.0004

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by