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 次查看(过去 30 天)
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)

回答(1 个)

dpb
dpb 2022-6-12
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
>>

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by