Solve for a variable in an equation?

79 次查看(过去 30 天)
A
A 2016-1-21
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 个评论
Walter Roberson
Walter Roberson 2016-1-22
编辑:Walter Roberson 2016-1-22
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 2016-1-22
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.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2016-1-22
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 个评论
A
A 2016-1-23
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 2016-1-23
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.)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by