Need help finding intercept in a polynomial function

16 ビュー (過去 30 日間)
Gerardo Flores Sempertegui
Gerardo Flores Sempertegui 2019 年 11 月 27 日
Hello,
I have a polynomial function and I would like to find all the "x" values for a "y" value.
For example I have tried to plot this function:
x=[0:0.05:23]
f=@(x) 152.094827571469-206.917405701416*x+188.571689289441*(x.^2)-93.85238987*(x.^3)+25.7783269818991*(x.^4)-4.34657779503011*(x.^5)+0.485315204*(x.^6)-0.0353709647924109*(x.^7)+0.00158130195601334*(x.^8)-0.0000388214150997567*(x.^9)+0.000000397986046326228*(x.^10)
y=f(x)
plot(x,y)
grid on
I have tried to do all the intercepts with the interp1 formula (for example when y=600)
x0=interp1(y,x,600,'nearest')
x1=interp1(y,x,600,'linear')
x2=interp1(y,x,600,'spline')
x3=interp1(y,x,600,'pchip')
x4=interp1(y,x,600,'cubic')
x5=interp1(y,x,600,'v5cubic')
As you can see in the graph I should get 2 points when y=600 but I only one and it is the same for all the y values I use.
matlabhelp.PNG
Please if you know any way to find all the interceptions when y=600 or any value it would be very helpful!
Thank you for your time and help.

採用された回答

James Tursa
James Tursa 2019 年 11 月 27 日
編集済み: James Tursa 2019 年 11 月 27 日
Why can't you just find the real roots of f(x)-600? What am I missing here?
  2 件のコメント
Guillaume
Guillaume 2019 年 11 月 27 日
Indeed, and that would be trivial to do if the polynomial was expressed as a vector of coefficients instead of being hardcoded in an anonymous function:
p = fliplr([152.094827571469;
-206.917405701416;
188.571689289441;
-93.85238987;
25.7783269818991
-4.34657779503011
0.485315204
-0.0353709647924109
0.00158130195601334
-0.0000388214150997567
0.000000397986046326228].')
f = @(x) polyval(p, x);
r = roots(p - [zeros(1, 10), 600]);
r(imag(r) == 0)
Gerardo Flores Sempertegui
Gerardo Flores Sempertegui 2019 年 11 月 28 日
Hi Guillaume, that solved my problem! Thank you!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by