Solve an expression including a function

1 回表示 (過去 30 日間)
Aurélien PAULMIER
Aurélien PAULMIER 2012 年 8 月 5 日
Is it possible to use "solve" for an expression including a function? E.g. solve('expression=f(function(x)))','x') Thanks

回答 (2 件)

Oleg Komarov
Oleg Komarov 2012 年 8 月 5 日
Bring everything to LHS:
solve('expression - f(function(x))','x')
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 8 月 5 日
And note that in order to get anything useful out of this, the function would have to have been defined in the symbolic toolbox. You might find it easier to work with
solve(expression - f(function(x)), x)
(but of course "function" is a reserved word so you could not use that as the name.)

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


Star Strider
Star Strider 2012 年 8 月 5 日
In 2012a, this:
syms a b c x y f(x) g(x)
f(x) = sin(x) + cos(x)
g(x) = x / (x^2 + 1)
soln = solve( g(x) == f(x), x)
yields:
soln =
-226.98318440505298644743940820481
Since I was also curious to see if this sort of syntax worked.
Substituting:
g(x) = exp(y)
soln = solve( g(x) == f(x), x)
yields:
soln =
-log(exp(y)*(1/2 + i/2) + (2^(1/2)*(exp(2*y)*i - 2*i)^(1/2))/2)*i
-log(exp(y)*(1/2 + i/2) - (2^(1/2)*(exp(2*y)*i - 2*i)^(1/2))/2)*i
to be sure that it also can return symbolic solutions. It also works using only the expressions, without the function syntax.
(I made these functions up for this illustration. To the best of my knowledge they have no practical application.)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by