Solve for a variable in an equation?
78 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a simple question. If I have the below example equation:
p = @(x,y) x.^2 * y.^2;
z = @(x,y) (p(x,y) + 3^9 + x.*y)./SQRT(p(x,y))
How can I solve for p? I want to basically find out what p(x,y) = ? I know that I define the variable, and I can probably do arithmetic to solve for it... but for very, very complex equations.. can matlab solve for a single variable?
Thanks
2 commentaires
Walter Roberson
le 22 Jan 2016
Modifié(e) : Walter Roberson
le 22 Jan 2016
I do not understand what information you are given? Are you given a particular z value, without x or y, and asked to find p?
If so, there are multiple solutions, such as
(1/4)*(z-1+sqrt(z^2-2*z-78731))^2
(1/4)*(1-z+sqrt(z^2-2*z-78731))^2
(1/4)*(-z-1+sqrt(z^2+2*z-78731))^2
(1/4)*(z+1+sqrt(z^2+2*z-78731))^2
Réponses (1)
Walter Roberson
le 22 Jan 2016
Have you looked at the Symbolic Toolbox?
There are expressions that cannot be solved for a closed form solution. For those the result of solve might involve a RootOf(). A RootOf() a polynomial of degree up to 4 can be solved in closed form, and RootOf() higher order polynomials can find all numeric solutions, RootOf() other things cannot necessarily find any numeric solutions.
2 commentaires
Walter Roberson
le 23 Jan 2016
syms A B C
eqn = A == B + C/B
sol = solve(eqn, B)
If you have an older version of the Symbolic Toolbox, you might need
syms A B C
eqn = (A) - (B + C/B)
sol = solve(eqn, B)
If you do not have the Symbolic Toolbox, then No, there is no way that will get you the general expression.
However, if you have particular numbers for the other names in the expression, then
A = 21; %example number
C = pi; %example number
eqn = @(B) (A) - (B + C/B); %left side minus right side
initial_guess = rand();
sol = fzero(eqn, initial_guess)
This will only work when all of the other values are known, and it will find at most one of the solutions (this particular equation has two solutions.)
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox 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!