MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   使用for循环进行多项式的曲线拟合,直到度i? (https://www.labfans.com/bbs/showthread.php?t=22479)

poster 2019-12-07 01:00

使用for循环进行多项式的曲线拟合,直到度i?
 
我有这个硬编码版本,可将数据拟合为线性,二次和三次多项式的曲线:

对于一些数据x和一个函数y

M=[x.^0 x.^1]; L=[x.^0 x.^1 x.^2]; linear = (M'*M)\(M'*y); plot(x, linear(1)+linear(2)*x, ';linear;r'); deg2 = (L'*L)\(L'*y); plot(x, deg2(1)+deg2(2)*x+deg2(3)*(x.*x), ';quadratic plot;b'); 我想知道如何将其转换为for循环以绘制n次多项式的曲线?我卡住的部分是绘图部分,如何将系数数量的增加转换为for循环?

是)我有的:

for i = 1:5 % say we're trying to plot curves up to degree 5 polynomials... curr=x.^(0:i); degI = (curr'*curr)\(curr'*y); plot(x, ???) % what goes in here


所有时间均为北京时间。现在的时间是 23:35

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.