Solve for a variable in an equation?

조회 수: 79 (최근 30일)
A
A 2016년 1월 21일
댓글: Walter Roberson 2016년 1월 23일
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에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by