Solving a Nonlinear Equation
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Walter Roberson
le 16 Avr 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.
Réponses (1)
Ayush
le 6 Nov 2024 à 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);
0 commentaires
Voir également
Catégories
En savoir plus sur Systems of Nonlinear Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!