我有这个带有一个独立变量的回归 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]);