當前位置:編程學習大全網 - 腳本源碼 - 急急急!!!matlab多項式的系數擬合問題!!!

急急急!!!matlab多項式的系數擬合問題!!!

用Poly5擬合即可:

Linear model Poly5:

fitresult(x) = p1*x^5 + p2*x^4 + p3*x^3 + p4*x^2 + p5*x + p6

妳的a0...a6與上式中的p6...p1相對應。

a0和a1由邊界條件確定,即p6、p5由邊界條件確定。

在下例中,設a0=p6=40、a1=p5=-5

% 以下代碼在7.1版以上均可運行

% 輸入原始數據 x y

x=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26];

y=[56 57 58 65 82 114 117 120 124 124 122 122 122 119 119 118 118 116 117 115 117 117 117 117 117 115];

xData = x(:);

yData = y(:);

% Set up fittype and options.

ft = fittype( 'poly5' );

opts = fitoptions( ft );

opts.Lower = [-Inf -Inf -Inf -Inf -5 40]; % 設 a0=p6=40 a1=p5=-5

opts.Upper = [Inf Inf Inf Inf -5 40]; % 設 a0=p6=40 a1=p5=-5

% Fit model to data.

[fitresult, gof] = fit( xData, yData, ft, opts )

% Plot fit with data.

figure( 'Name', '擬合圖' );

h_ = plot( fitresult, x, y, '* '); % 擬合圖 原始數據

legend off; % turn off legend from plot method call

set(h_(2),'Color',[1 0 0],...

'LineStyle','-', 'LineWidth',2,...

'Marker','none', 'MarkerSize',6);

h = legend('原始數據','擬合曲線',2,'Location','Best');

set(h,'Interpreter','none')

title('擬合圖 原始數據')

% Label axes

xlabel( 'x' );

ylabel( 'y' );

grid on

  • 上一篇:銷售公司晨會小故事及感悟
  • 下一篇:《升天號》劇情大概講了什麽?
  • copyright 2024編程學習大全網