Solving a Nonlinear Equation

7 visualizaciones (últimos 30 días)
David Oswalt
David Oswalt el 16 de Abr. de 2019
Respondida: Ayush el 6 de Nov. de 2024 a las 6:09
I have the following equation:
p41 = p21*(1 - ((g4 - 1)*(a1/a4)*(p21 - 1))/(sqrt((2*g1)*(2*g1 + (g1 + 1)*(p21 -1 )))))^((-2*g4)/(g4 - 1));
where p21 is the only unknown and the rest are all constants. This equation is difficult (or perhaps impossible, not sure) to solve analytically. When solving problems by hand using this equation, we were taught to "guess and check" using trial and error by iteration. If I were to attempt to solve this equation for p41 using Matlab 2016b, what would be the best way to do so?
I have attempted:
syms p21
eqn = p21*(1 - ((g4 - 1)*(a1/a4)*(p21 - 1))/(sqrt((2*g1)*(2*g1 + ...
(g1 + 1)*(p21 -1 )))))^((-2*g4)/(g4 - 1)) == p41;
solx = solve(eqn,p21)
which returns a crazy 11x1 sym full of polynomials in terms of z. Is this equation not solveable analytically using Matlab? If so, what would be the best way to solve it iteratively for p21, given all other values are constant?
Thanks a lot!
  1 comentario
Walter Roberson
Walter Roberson el 16 de Abr. de 2019
solx = solve(eqn, p21, 'returnconditions', true);
and then check whether solx.Parameters is empty or not. If it is not empty, then solx.p21 will refer to the variables named in solx.Parameters, and solx.Conditions will define the restrictions on those variables.

Iniciar sesión para comentar.

Respuestas (1)

Ayush
Ayush el 6 de Nov. de 2024 a las 6:09
You can use fsolve to solve such complex equation as it allows you to solve nonlinear equations numerically.
Here is the sample code for the same:
% Define constants
g1 = ...; % define your value
g4 = ...; % define your value
a1 = ...; % define your value
a4 = ...; % define your value
p41 = ...; % define your value
% Define the function to solve
equation = @(p21) p21 * (1 - ((g4 - 1) * (a1 / a4) * (p21 - 1)) / ...
sqrt((2 * g1) * (2 * g1 + (g1 + 1) * (p21 - 1))))^((-2 * g4) / (g4 - 1)) - p41;
% Initial guess for p21
initial_guess = 1;
% Solve using fsolve
options = optimoptions('fsolve', 'Display', 'iter');
[p21_solution, fval, exitflag] = fsolve(equation, initial_guess, options);
You can read more about fsolve from here: https://www.mathworks.com/help/optim/ug/fsolve.html

Categorías

Más información sobre Systems of Nonlinear Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by