MATLAB Answers

0

How to write the equivalent of an 'until loop' in matlab?

Asked by McNugget on 3 Apr 2016
Latest activity Commented on by Walter Roberson
on 3 Apr 2016
if T>=673
U=(4*11.3)/(5000*0.0762);
"until T=593"
else U=1/(298-T);
end;
Basically I want to be able to say until T = 593 but in a way understood by Matlab.
The whole code is such:
function f = dndw(w,n)
b=n(1);
o=n(2);
bd=n(3);
h=n(4);
co=n(5);
T=n(6);
k1=(85)*exp(-53100/(8.314*T));
k2=(9944444.444)*exp(-128300/(8.314*T));
k3=(8722222.222)*exp(-154700/(8.314*T));
k4=(95000000)*exp(-156000/(8.314*T));
np=4.317;
nn=639.2;
nt=b+o+bd+h+np+co+nn;
P=202.650;
pb=(b/nt)*P;
po=(o/nt)*P;
pbd=(b/nt)*P;
r1=(k1*k2*(po^0.5)*pb)/(0.5*k1*pb+k2*(po^0.5));
r2=k3*(po^0.7)*(pb^0.25)*(pbd^-0.86);
r3=k4*(po^0.25)*(pbd^0.85);
dbdw=-r1-r2;
dodw=-0.5*r1-6*r2-5.5*r3;
dbddw=r1-r3;
dhdw=r1+4*r2+3*r3;
dcodw=4*r2+4*r3;
***dTdw=(U*(493-T)*((165170.736*r1)+(2711247*r2)+(2431510*r3)))/(40*nt)***;
f=[dbdw;dodw;dbddw;dhdw;dcodw;dTdw];
end
Thanks!

  0 Comments

Sign in to comment.

Tags

2 Answers

Answer by Azzi Abdelmalek
on 3 Apr 2016

  2 Comments

I've tried but perhaps I'm not understanding. Could you perhaps show me how?
Thanks!
%Example: calcul the sum s= 1+2+3+...+n with s<=1000
s=0;
k=1;
while k<1000
k=2*k
s=s+k
end

Sign in to comment.


Answer by Roger Stafford on 3 Apr 2016

To reproduce the equivalent of repeat --- until in C, do this:
b = true;
while b
do the loop computations
b = ~until % <-- Form the logical "NOT" of the desired "until" condition
end

  1 Comment

Alternately but equivalently:
while true
do the loop computations
if TheCondition
break;
end
end

Sign in to comment.