Error in for loop calculation

조회 수: 1 (최근 30일)
Avinav Kumar
Avinav Kumar 2021년 3월 30일
편집: Stephen23 2021년 3월 30일
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

채택된 답변

Stephen23
Stephen23 2021년 3월 30일
편집: Stephen23 2021년 3월 30일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by