How to compute several results from incremental input values using loops?

1 Ansicht (letzte 30 Tage)
EEC CTU
EEC CTU am 18 Nov. 2019
Bearbeitet: KALYAN ACHARJYA am 18 Nov. 2019
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 Kommentar
KALYAN ACHARJYA
KALYAN ACHARJYA am 18 Nov. 2019
Bearbeitet: KALYAN ACHARJYA am 18 Nov. 2019
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KSSV
KSSV am 18 Nov. 2019
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) ;

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by