フィルターのクリア

Solve for a variable in an equation?

26 ビュー (過去 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 Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by