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

2 ビュー (過去 30 日間)
Eslam Zaky
Eslam Zaky 2022 年 6 月 12 日
編集済み: Voss 2022 年 6 月 12 日
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
>>

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by