Iterating an equation using while loop

I have an equation describing Area ratio of a nozzle and exit Mach number
Area_ratio = (1/Mach_number)*((2/(k+1))*(1+((k-1)/2)*(Mach_number)^2))^((k+1)/(2*k-1))
I want to be able to input an area ratio and get the corresponding mach number as the output. The equation is too complex to rearrange, and I cant figure out how to create an iterative loop to solve it. This is what I attempted:
Ar = 50
Ma_guess = 0.1 % Initial Mach number guess
Ar_guess = Ar_guess = (1/Ma_guess)*((2/(k+1))*(1+((k-1)/2)*(Ma_guess)^2))^((k+1)/(2*k-1)) % Initial Area Ratio Guess
while Ar_guess < Ar
Ma_guess = Ma_guess + 0.01 ;
Ar_guess = Ar_guess = (1/Ma_guess)*((2/(k+1))*(1+((k-1)/2)*(Ma_guess)^2))^((k+1)/(2*k-1)) ;
end
Ma = Ma_guess
I know it's wrong but gives you a bit of an idea of what I'm trying to do.
All help would be much appreciated.
Kind regards,
barney

回答(1 个)

Torsten
Torsten 2022-4-20
编辑:Torsten 2022-4-20
k = 1.4;
Ar = 50;
Ma_guess = 0.1; % Initial Mach number guess
fun = @(M) Ar - (1/M)*((2/(k+1))*(1+((k-1)/2)*(M)^2))^((k+1)/(2*k-1));
Ma = fzero(fun,Ma_guess)

类别

帮助中心File Exchange 中查找有关 Mathematics 的更多信息

产品

版本

R2022a

编辑:

2022-4-20

Community Treasure Hunt

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

Start Hunting!

Translated by