How do for loop and stop when code is catch error 1e-6, and please i need to check following code to get "M1" Value

3 views (last 30 days)
for M1=.1:.1:10
e1=0.0045/.00264;
e2=((2+.135*M1^2)/(2.135))^(2.135/(4*.135))*(1/M1)^0.5;
while abs(e1-e2)~= 1e-4
continue
if abs(e1-e2)== 1e-4
break
end
end
end
fprintf('%3u',M1)

Answers (1)

dpb
dpb on 12 Jun 2022
e1=0.0045/.00264;
fnF=@(M1)((2+0.135.*M1.^2)./(2.135)).^(2.135./(4*0.135)).*(1./M1).^0.5-e1;
fplot(fnF,[0.1 3])
shows zero crossings around 0.2 and 2
>> fsolve(fnF,0.2)
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
ans =
0.2102
>> fsolve(fnF,2)
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
ans =
2.3012
>> doc fsolve
>>

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!