Error in for loop calculation
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!