フィルターのクリア

How to find the solution of inverse function ?

26 ビュー (過去 30 日間)
SeokWon CHOI
SeokWon CHOI 2020 年 11 月 24 日
コメント済み: Stephan 2020 年 11 月 24 日
Hello, I have some question for solving matlab.
if x = [1 2 3 4 5 6 7] and y = [3.6 1.8 1.2 0.9 0.72 1.5 0.51429]
I want to find f(x) = 1.7 and inverse of f(1.7) (quadratic form)
The code I implemented is
>> x = [1 2 3 4 5 6 7]; y = [3.6 1.8 1.2 0.9 0.72 1.5 0.51429];
>> p = polyfit(x,y,2);
>> syms x;
>> fx = p(1)*x^2 + p(2)*x + p(3);
>> gx = finverse(fx,x);
>> gx(1.7) // error! (The index exceeds the number of array elements (1).)
Why does gx(1.7) throw an error? What should I do for getting gx(1.7) ?

採用された回答

Stephan
Stephan 2020 年 11 月 24 日
x = [1 2 3 4 5 6 7];
y = [3.6 1.8 1.2 0.9 0.72 1.5 0.51429];
p = polyfit(x,y,2)
syms x
fx(x) = poly2sym(p)
gx(x) = finverse(fx)
sol = gx(1.7)
sol_num = double(sol)
  2 件のコメント
SeokWon CHOI
SeokWon CHOI 2020 年 11 月 24 日
Thank you, sir! solve it !
but I don't know why my code has error.
and what is the poly2sym? I don't learn about this function.
Could you explain me?
Stephan
Stephan 2020 年 11 月 24 日
poly2sym creates symbolic polynomial from vector of coefficients - this is what you need to do here. Also there are 2 different symbolic data types namely sym and symfun, which lets you calculate values with symbolic functions.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by