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

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

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2019년 11월 18일

편집:

2019년 11월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by