简体   繁体   中英

Solving a nonlinear equation numerically

I have the following equation to solve:

 aRatio = ((sqrt_gamma_ratio * (1/m) * ((1 + (squared_m_coefficient * m^2))^num_exponent))/ denom);

where variables aRatio , sqrt_gamma_ratio , squared_m_coefficient , num_exponent , and denom are all known constants (1, 1.046, .14, 4.07, and 1.728, respectively). Just before the code above, m is defined symbolically. It's a portion of some code of mine that includes iteration, so I need some help coming up with a generalized approach to approximate m (doesn't have to be too accurate, I'd say to the hundredths place is fine). I've tried using the vpasolve function as follows:

f = vpasolve(aRatio == ((sqrt_gamma_ratio * (1/m) * ((1 + (squared_m_coefficient * m^2))^num_exponent))/ denom), m);

but it just returns

Empty sym: 0-by-1

So, Matlab doesn't seem to be able to solve it symbolically. I'm guessing I have to take the numerical approach, which I'm much less familiar with. The long term objective is to establish m as a function of aRatio . Eventually I hope to create an array of values for aRatio , whose range will be from 1-1000, in intervals of 10. This way I can (hopefully) generate a plot of aRatio vs. m . This will be accomplished through iteration with a while loop. I plan on changing a few other variables, but I think if I can get help with just this portion of the problem, it could go a long way.

My question is why can't Matlab solve this relatively simple equation symbolically and what alternatives do I have? I've googled this extensively and I am very confused.

EDIT: here is the relevant code

gam0 = 1.4; %specific heat ratio in middle of nozzle
gamE = 1.28:-.01:1.20 ; %establish exit sp heat ratio variation
denom = 1.728; % this is the denominator of the given eqn, evaluated at g* = 
1.4
aRatio = 1:10:1001;
count = 1;
mach_number = zeros(1,length(aRatio));

the following code is for debugging purposes, it belongs in the while loop. I presume that I need a nested while loop to iterate the gamE, but that really isn't my issue right now. All I want is to get a value back for m, which I've yet to do at all

sqrt_gamma_ratio = sqrt(gam0 / gamE(1)); %1.046
squared_m_coefficient = .5 * (gamE(1) - 1); %.14
num_exponent = (gamE(1) + 1)/(2 * (gamE(1) - 1)); %4.07

Note: the values stored above are just from the first iteration of gamE, and will be iterated in the finish product as well, but I'm pretty comfortable with loops; it's Matlab that's giving me headaches!

f =((sqrt_gamma_ratio * (1/m) * ((1 + (squared_m_coefficient* 
m^2))^num_exponent))/ denom)-aRatio;
fn = fzero(matlabFunction(f),1);

when I run, I get this:

Operands to the || and && operators must be convertible to logical scalar values.

I'll be honest I have no idea what that means or how to fix it. I imagine I HAVE to be close at least?

Below is just the while loop I hope to one day complete. For those of you who are interested I'm trying to get roughly 8000 data points, I'll store them all one array, but it's basically ALL ABOUT finding m as a function of aRatio, and once I get that figured out I just have to iterate the gamE variable above, which should be a piece of cake. PS you can laugh at my unsatisfactory loop below if you like.

%{
while( count < length(compressive_area_ratio)+1 )

    sqrt_gamma_ratio = sqrt(gam0 / gamE(1));
    squared_m_coefficient = .5 * (gamE(1) - 1);
    num_exponent = (gamE(1) + 1)/(2 * (gamE(1) - 1));
    this_M = solve(compressive_area_ratio(count) == ((sqrt_gamma_ratio * 
(1/m) * ((1 + (squared_m_coefficient * m^2))^num_exponent))/ denom), m );
    disp(this_M);
    %mach_number(count) = this_M;
    count = count + 1;   
end
%}

%plot(compressive_area_ratio, mach_number);

Any ideas ?

You used vpasolve , but claim that it did not work, so I decided to test solve, and then vpa , and this is what I get:

gam0 = 1.4; %specific heat ratio in middle of nozzle
gamE = 1.28; %establish exit sp heat ratio variation
denom = 1.728; % this is the denominator of the given eqn, evaluated at g* = 1.4
aRatio = 1;
count = 1;
mach_number = zeros(1,length(aRatio));


sqrt_gamma_ratio = sqrt(gam0 / gamE(1)); %1.046
squared_m_coefficient = .5 * (gamE(1) - 1); %.14
num_exponent = (gamE(1) + 1)/(2 * (gamE(1) - 1)); %4.07


syms m
sol=solve(((sqrt_gamma_ratio * (1/m) * ((1 + (squared_m_coefficient * m^2))^num_exponent))/ denom)-aRatio);
vpa(sol)

   > 4.3269393310990630350495077697516i

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM