How to compute several results from incremental input values using loops?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, I'm new to MATLAB and I'm writing a program to compute a solar cell's operating temperature at different ambient temperature and a fixed solar irradiation levels. Say I want to compute Tcell starting at 32 until the value of X (where X = 32 + 0.2*N, N is number of iterations), so yeah basically it increments 32 by 0.2 and stops at a value X.
Here's my code btw but it's very messed up:
clc
I = input('Enter solar irradiance here: ');
A = input('Enter ambient temperature here: ');
N = input('Enter number of iterations to perform: ');
disp(' Ambient Temp NOCT Tcell ')
n = 1;
nFinal = N + 1;
i = 1;
S = I*0.1;
NOCT = 0.0174*I + 20;
format long
while (n <= nFinal)
Tc = A + (NOCT - 20) * (S/80);
disp([A NOCT Tc])
if (abs(Tc) <= 1E-6)
nFinal = n;
break;
end
n = n + 1
i = i + 1
end
1 件のコメント
KALYAN ACHARJYA
2019 年 11 月 18 日
編集済み: KALYAN ACHARJYA
2019 年 11 月 18 日
I couldn't find the same logic in the code and expressed by the text. Note, one should always use the same variable name to text and code, so that the code is easily understood.
回答 (1 件)
KSSV
2019 年 11 月 18 日
x0 = 32 ;
dx = 0.2 ;
N = 20 ; % iterations needed
for i = 1:N
x = x0+(i-1)*dx ;
end
YOu can avoid for loop using:
x0 = 32 ;
dx = 0.2 ;
N = 20 ;
x = x0:dx:(x0+(N-1)*dx) ;
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!