I'm trying to interate static pressure ratio to find Mach number using fsolve, but I can't get the syntax correct. The Mathworks explaination didn't really help me. Could anyone out there help?
I have a set range for the pressure ratio, but the Mach number is unknown. Here is the equation:
Capture.PNG
This is what I have so far for the code:
pt2pinf = [1.9, 2.7, 3.5, 4.3, 5.1, 5.9, 6.7, 7.5, 27.5, 47.5, 67.5 ,87.5 ,107.5,127.5, 147.5, 200, 252.5, 305, 357.5, 410, 462.5 ,515 ,567.5, 620, 672.5, 725, 777.5, 830 ,882.5, 935, 987.5, 1000];
Me0=ones(1,32);
g=1.2;
pt2pinf_test = fsolve(@(Me)(((1+((g-1)/2)*Me.^2)^(g/(g-1)))/((((2*g)/(g+1))*Me.^2)-((g-1)/(g+1)))),Me0);

8 件のコメント

Torsten
Torsten 2019 年 9 月 10 日
編集済み: Torsten 2019 年 9 月 10 日
In the function you passed to "fsolve", you forgot to subtract the pressure ratio.
And for all ^, / and * operators, use .^, ./ and .* (elementwise operation).
Hailey
Hailey 2019 年 9 月 10 日
So it should look like this? But I get an error doing this. I'm sorry, I'm still confused. Because I have Me0 set as ones, should it be zeros while fsolve is trying to solve the problem?
pt2pinf_test = fsolve(@(Me)((((1+((g-1)/2).*Me.^2)^(g/(g-1)))/((((2*g)/(g+1)).*Me.^2)-((g-1)/(g+1))))-pt2pinf),Me0);
Torsten
Torsten 2019 年 9 月 10 日
You did not substitute all ^ by .^ and all / by ./ .
Hailey
Hailey 2019 年 9 月 10 日
I'm getting this, but I have the same array size:
Equation solved, fsolve stalled.
fsolve stopped because the relative size of the current step is less than the
value of the step size tolerance squared and the vector of function values
is near zero as measured by the value of the function tolerance.
<stopping criteria details>
Torsten
Torsten 2019 年 9 月 10 日
Thus you were successful.
Hailey
Hailey 2019 年 9 月 10 日
編集済み: Hailey 2019 年 9 月 10 日
But I need to have the Mach number values. I need an array of Mach numbers that match up with it's respective pressure ratio value. This did not do that.
Torsten
Torsten 2019 年 9 月 10 日
They are stored in the fsolve return parameter (pt2pinf_test in your case).
Hailey
Hailey 2019 年 9 月 10 日
編集済み: Hailey 2019 年 9 月 10 日
The values are too small to be a Mach number after a shock wave.
Not sure what I did wrong.

サインインしてコメントする。

 採用された回答

Torsten
Torsten 2019 年 9 月 10 日
編集済み: Torsten 2019 年 9 月 10 日

0 投票

function main
pt2pinf = [1.9, 2.7, 3.5, 4.3, 5.1, 5.9, 6.7, 7.5, 27.5, 47.5, 67.5 ,87.5 ,107.5,127.5, 147.5, 200, 252.5, 305, 357.5, 410, 462.5 ,515 ,567.5, 620, 672.5, 725, 777.5, 830 ,882.5, 935, 987.5, 1000];
Me0 = 5.0;
g = 1.2;
fun = @(Me,pquot)((((1+((g-1)/2)*Me.^2).^(g/(g-1)))./((((2*g)/(g+1))*Me.^2)-((g-1)/(g+1))))-pquot).^2
for i = 1:numel(pt2pinf)
pquot = pt2pinf(i);
machnumber(i) = fminsearch(@(Me)fun(Me,pquot),Me0,optimset('TolFun',1e-10));
end
machnumber
fun(machnumber,pt2pinf)
end

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Physics についてさらに検索

質問済み:

2019 年 9 月 10 日

編集済み:

2019 年 9 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by