Borrar filtros
Borrar filtros

Solve for a variable in an equation?

22 visualizaciones (últimos 30 días)
A
A el 21 de En. de 2016
Comentada: Walter Roberson el 23 de En. de 2016
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 comentarios
Walter Roberson
Walter Roberson el 22 de En. de 2016
Editada: Walter Roberson el 22 de En. de 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
A
A el 22 de En. de 2016
I just meant that... can I use matlab to solve for a certain variable in any complex equation in the mould of z(x,y) = x + y + many constants,variables,etc.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 22 de En. de 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 comentarios
A
A el 23 de En. de 2016
I used square root as just an example. I just want there to be a way to solve for a certain variable in an equation. For example,
A = B+C/B
I know that I can do simple algebra, but is there a matlab method which allows me to solve for 'B'?
Thank you! sorry for confusion.
Walter Roberson
Walter Roberson el 23 de En. de 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.)

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by