我有一个独立变量回归的matlab代码,但是如果我有两个独立变量(x1和x2)呢?我应该如何修改这个多项式回归的代码?
x = linspace(0,10,200)'; % independent variable
y = x + 1.5*sin(x) + randn(size(x,1),1); % dependent variable
A = [x.^0, x]; % construct a matrix of permutations
w = (A'*A)\(A'*y); % solve the normal equation
y2 = A*w; % restore the dependent variable
r = y-y1; % find the vector of regression residual
plot(x, [y y2]);发布于 2011-07-23 05:54:11
Matlab具有多项式回归函数polyfit的功能。你试过吗?
http://www.mathworks.com/help/techdoc/data_analysis/f1-8450.html
http://www.mathworks.com/help/toolbox/stats/bq_676m-2.html#bq_676m-3
但是,如果你想制定自己的公式,你可能应该看看教科书或一些关于回归的在线资源。
http://www.edwardtufte.com/tufte/dapp/DAPP3a.pdf
https://stackoverflow.com/questions/6796316
复制相似问题