How to solve an equation in terms of the other variable

80 ビュー (過去 30 日間)
Phil
Phil 2012 年 12 月 11 日
回答済み: Jeffery Devereux 2018 年 2 月 26 日
I have the equation g^2+6*g*h+3h=0 for which I need to solve g in terms of h. Here is my attempt:
syms g h
g = solve('g^2+6*g*h+3*h=0')
For some reason this consistently only solves h in terms of g. Can someone point out to me what I am doing wrong?

採用された回答

Walter Roberson
Walter Roberson 2012 年 12 月 11 日
solve() has an algorithm for selecting which variable to solve for when it is not told which one to solve for. The algorithm is based upon the letter the variable name starts with.
You should specify which variable you want solved for:
g = solve('g^2+6*g*h+3*h=0', 'g')
  1 件のコメント
Phil
Phil 2012 年 12 月 11 日
Thank you very much. Quite helpful.

サインインしてコメントする。

その他の回答 (1 件)

Jeffery Devereux
Jeffery Devereux 2018 年 2 月 26 日
you need to use two equal signs
g^2+6*g*h+3*h==0

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by