Error in for loop calculation

2 views (last 30 days)
Avinav Kumar
Avinav Kumar on 30 Mar 2021
Edited: Stephen23 on 30 Mar 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

Accepted Answer

Stephen23
Stephen23 on 30 Mar 2021
Edited: Stephen23 on 30 Mar 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

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!