Iterating an equation using while loop
Afficher commentaires plus anciens
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
Réponses (1)
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)
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!