Please Help - How do I solve this for M

2 vues (au cours des 30 derniers jours)
Saumya Nagar 17BME0447
Saumya Nagar 17BME0447 le 21 Mar 2021
Modifié(e) : John D'Errico le 21 Mar 2021
I am a bit new to Matlab, I have to solve the following equation for M,
A/B=(1/M)*((2/(G+1)*(1+((G-1)/2)*M^2)))^((G+1)/(2*(G-1)))
Here all the other variables than M (i.e. A, B and G) are known. I need to find the value of M. I tried out with the below code, but it did not work.
eqn=A/B-(1/M)*((2/(G+1)*(1+((G-1)/2)*M^2)))^((G+1)/(2*(G-1)))==0;
solx=solve(eqn,M)
The output came as:
solx =
root(z^6 + 15*z^4 + 75*z^2 - 432*z + 125, z, 1)
root(z^6 + 15*z^4 + 75*z^2 - 432*z + 125, z, 2)
root(z^6 + 15*z^4 + 75*z^2 - 432*z + 125, z, 3)
root(z^6 + 15*z^4 + 75*z^2 - 432*z + 125, z, 4)
root(z^6 + 15*z^4 + 75*z^2 - 432*z + 125, z, 5)
root(z^6 + 15*z^4 + 75*z^2 - 432*z + 125, z, 6)
The correct output should be a number. Can anyone please help me in this.
Thanks in advance!

Réponses (1)

John D'Errico
John D'Errico le 21 Mar 2021
You need to understand that solve is a solver that will produce an analytical solution if possible. And this apparently reduces to something equivalent to a 6th degree polynomial, so there are 6 roots described. The problem is you cannot solve for a general 6th degree polynomial with the roots in an algebraic form.
What you can do is use vpa to tell MATLAB to reduce the problem to a numerical one. Try
vpa(solx)
  2 commentaires
Saumya Nagar 17BME0447
Saumya Nagar 17BME0447 le 21 Mar 2021
Modifié(e) : Saumya Nagar 17BME0447 le 21 Mar 2021
Hi John,
Thank you for your help. It now shows the below error. Can you please help me to resolve it. Thanks!
Error using digits (line 42)
The input must be a positive integer larger than 1 and smaller than 2^29 + 1.
Error in sym/vpa (line 30)
digits(d);
Error in first (line 20)
solx=vpa(solx,M)
The entire code is:
clc;
clear all;
format short;
syms M;
G = input('Enter the value of Gamma of the gas used (for monoatomic=1.66, for diatomic=1.4) : ' );
Molecular_Weight=input('Enter the molecular weight of the gas used in grams/mole (for air=28.97): ' );
Stagnation_Temperature = input('Enter the value of Stagnation Temperature in Kelvins : ' );
Mass_Flow_Rate= input('Enter the mass flow rate: ' );
Exit_Area= input('Enter the exit area: ' );
R=8314.46261815324/Molecular_Weight
Throat_Temperature=(2*Stagnation_Temperature)/(G+1)
Throat_Velocity=sqrt(G*R*Throat_Temperature)
Throat_Area=1;
Throat_Density=Mass_Flow_Rate/(Throat_Velocity*Throat_Area)
Throat_Pressure=Throat_Density*R*Throat_Temperature
Stagnation_Pressure=Throat_Pressure*((G+1)/2)^(G/(G-1))
solx=Exit_Area/Throat_Area-(1/M)*((2/(G+1)*(1+((G-1)/2)*M^2)))^((G+1)/(2*(G-1)))==0;
%solx=solve(eqn,M)
solx=vpa(solx,M)
John D'Errico
John D'Errico le 21 Mar 2021
Modifié(e) : John D'Errico le 21 Mar 2021
Thats funny. Did I essentially tell you to write this:
solx=vpa(solx,M)
Or, this?
solx=vpa(solx)
I could swear it was the latter. In fact, when I look at my answer, that is clearly what I said. But I could be wrong.
Note that in your code, you did not even use solve. This solves for nothing:
solx=Exit_Area/Throat_Area-(1/M)*((2/(G+1)*(1+((G-1)/2)*M^2)))^((G+1)/(2*(G-1)))==0;
vpa is not solver. It merely reduces the result to a numerical form. solve and vpasolve are solvers. So you MIGHT do:
solx = solve(eqn,M);
solx = vpa(solx);
OR you might do this:
solx = vpa(solve(eqn,M));
OR you might do this:
solx = vpasolve(eqn,M);
The latter works because vpasolve is a numerical solver, so you need not apply vpa to the result.
Go slowly. Look at what you type. It will even help if you read the help for what you use. The odds will now become stronger that you get valid results.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by