Output values from a loop
이전 댓글 표시
Hello, i have a question. I want to change my the value of E, let the inner loop run and read out the last value of r. And this for every value of E and then plot r it in function of E. But I got some problems with this. This is what I got so far. If someone can help me with this I would be soo greatfull!!
clear all
format long;
W=input('InitieelW? ')
syms x
%W= input('w?');
for j=1:5;
E=110000+j*10000;
for i=1:5;
k= 0.132;
h= 20;
Bi= h*W/k;
R= 8.314;
Tp= 463.15;
Ta= 295.15;
A= 2.7*10^16;
rho= 993.5;
H = 4.51*10^5;
t = E/(R*Tp^2)*(Ta-Tp); %theta a
N = x/(2*Bi)+ t/2;
y = 2*(1-x*coth(x))*(cosh(x)-cosh(N))+x/(2*Bi)*exp(-N)+(1-coth(x)/(2*Bi))*x*sinh(x);
YM = matlabFunction(y);
P = fzero(YM,3); %3 is the initial guess
M = P/(2*Bi)+t/2;
deltacrit = (P^2/sinh(P)^2)*exp(-M)*(cosh(P)-cosh(M));
r= ((k*R*Tp^2*deltacrit)*exp(E/(R*Tp))/(E*A*rho*H))^(1/2);
i=i+1;
end;
r(j)=r
j=j+1
end
댓글 수: 1
Robert Cumming
2011년 5월 10일
what problems you "got"?
답변 (2개)
Andrew Newell
2011년 5월 10일
0 개 추천
Do you use the MATLAB Editor? You should because it has some very useful diagnostics. Look at the right margin of the editor and you will see some little orange lines. Hover the mouse over each line and you will see some warnings. I see two warnings relating to changing an index inside a FOR loop. These may be part of your problem.
Oleg Komarov
2011년 5월 10일
0 개 추천
The inner loop is completely unnecessary as you designed it. No variable changes as "i" varies. In addition to that you increment "i" itself at the end (why/what for?).
The only thing that varies is E and we don't know what matlabFunction does (thus can't say if it is vectorizable)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!