フィルターのクリア

Saving a polynomial function

3 ビュー (過去 30 日間)
Mak Dukan
Mak Dukan 2021 年 11 月 1 日
回答済み: Walter Roberson 2021 年 11 月 1 日
Hi all,
I have a simple question. How can I save a polynomial function? By this I mean somethign like "p(x)=p1xn+p2xn−1+...+pnx+pn+1", however with all the coeficients and powers? I need to fit multiple curves and would like to avoid having to type the equation every single time.
Here is the code I am using for an example:
p = polyfit(CapFac_DEAll_2019_sorted,HornsRevB_Prc_sort,5);
y1 = polyval(p,CapFac_DEAll_2019_sorted);
Fig1 = figure('Name','HornsRevB vs All DE for 2019');
scatter(CapFac_DEAll_2019_sorted, HornsRevB_Prc_sort,16,'r');
hold on
plot (CapFac_DEAll_2019_sorted,y1,'--b');
hold off
As you can see I am using first polyfit and then polyval to plot the curve and see if its a good fit.
I need these functions to multiply other timeseries values with them.
Thanks,
Mak

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 11 月 1 日
Just save the p variable. It is an ordered list of coefficients, highest degree first. You can use polyval() and polyder()
If you have the symbolic toolbox, you an also use poly2sym() to get an expression that you could either save or use matlabFunction() with (possibly with the 'File' option.)

カテゴリ

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

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by