Output values from a loop
Show older comments
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 Comment
Robert Cumming
on 10 May 2011
what problems you "got"?
Answers (2)
Andrew Newell
on 10 May 2011
0 votes
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
on 10 May 2011
0 votes
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)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!