MATLAB: Loop equation solver help

equation solverequationslooploopssolver

Hi what I am wanting to do is solve for delta where it is less than or equal to .01 by varing c and CMFR. So an example would be the code starts with c=50, it will then run through CMFR between 55 and 115. If delta never is less than or equal to .01 the code will then move on to c=51 and run CMFR between 55 and 150. This repeats until a c and CMFR are found where delta is less than or equal to .01 where it will stop. I need help with what loop statments to use, and where to use them. Any help is appreacated.
a=input('Off Design % RPM ');
Nc=Ncr*(a/100);
Nt2=Nc/((TT2r/Tstp)^.5);
c=50;
Loop1 (delta < .01)
loop2 (c is varied between 50 and 130)
Pc=Pcr*(c/10);
CMFR=55;
loop3 (CMFR is varied between 55 and 115)
Mdotc2=Mdotc2r*(CMFR/10);
tcg=Pc^((g-1)/g);
Nt4=(Mdotc2*(1/Pc)*Nt2);
Tt4=TT2r*((Nt2/Nt4)^.5);
tt=1-(1/(Tt4/TT2r))*(tcg-1);
Pt=abs(((1-tt)/ntr)-1)^(g/(g-1));
mmc2=(((Tt4/TT2r)*tt)^.5)*(1/(Pc*Pt));
CMFR=CMFR+.01;
delta=abs(mmc2-mmc2r);
end
c=c+.01;
end
end

Best Answer

Use meshgrid and surf
remember about element-wise operators (.* ./ and so on) LINK
a=input('Off Design % RPM ');
Nc=Ncr*(a/100);
Nt2=Nc/((TT2r/Tstp)^.5);
c1 = 50:130;
cmfr1 = 55:115;
[c,CMFR] = meshgrid(c1,cmfr1); % combination of 'c1' and 'cmfr1'
Pc=Pcr*(c/10);
Mdotc2=Mdotc2r*(CMFR/10);
tcg=Pc^((g-1)/g);
Nt4=(Mdotc2*(1/Pc)*Nt2);
Tt4=TT2r*((Nt2/Nt4)^.5);
tt=1-(1/(Tt4/TT2r))*(tcg-1);
Pt=abs(((1-tt)/ntr)-1)^(g/(g-1));
mmc2=(((Tt4/TT2r)*tt)^.5)*(1/(Pc*Pt));
delta = abs(mmc2-mmc2r);
ix = delta <= 0.01;
surf(c,CMFR,delta,'facecolor','none')
hold on
plot3(x(ix),CMFR(ix),delta(ix),'.r')
hold off