![]() |
使用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.