MATLAB Answers

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

조회 수: 2(최근 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
KALYAN ACHARJYA 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.

로그인 to comment.

답변 수 (1)

KSSV
KSSV 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) ;

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

제품


릴리스

R2018a

Translated by