简体   繁体   English

在Matlab中使用最小二乘法求解多维方程

[英]solve multidimensional equation using least square method in matlab

How do I get the coefficient a and b from this equation using least square method? 如何使用最小二乘法从该方程式获得系数ab What is the best way to solve this? 解决此问题的最佳方法是什么?

在此处输入图片说明

Let's say θ(k1,k2) is a matrix of 60x60 (constant/values), that is theta=rand(60,60) , but 假设θ(k1,k2)是一个60x60的矩阵(常数/值),即theta=rand(60,60) ,但是

在此处输入图片说明

How do I solve for a and b in matlab? 如何在Matlab中求解ab Any easy function to do it? 有任何简单的功能吗?

Thanks in advance! 提前致谢!

Reference paper: Here (section III) 参考文件: 此处 (第三节)

You can use the regress function to do this. 您可以使用回归函数执行此操作。 Here is an example: 这是一个例子:

% Generate an example
n = 60;
theta = rand(n);

% Create regressors
[M,N] = meshgrid(1:n,1:n);
X = [M(:), N(:)];

% Regress
B=regress(theta(:), X);

% Compare the results
theta_hat = reshape(X*B,n,n);
plot3(M,N,theta,'o');
hold on;
surf(M,N,theta_hat);

Notice that the regression is done on theta(:) which is a (3600,1) vector containing the values of theta(k1,k2) uses the corresponding coordinates in X which is (3600,2). 请注意,回归是在theta(:)上完成的,它是一个包含theta(k1,k2)值的(3600,1)向量,它使用X中的相应坐标为(3600,2)。 The first column of X is k1, the second is k2. X的第一列是k1,第二列是k2。

The result of calling regress gives you B=[a;b] the coefficients that best fit the data in theta. 调用回归的结果为您提供最适合数据theta的系数B=[a;b]

One final note is that the least squares could be solved directly using 最后一点是最小二乘法可以直接使用

B=inv(X'*X)*X'*theta(:)

which should give the same result, but regress is the preferred MATLAB method. 应该给出相同的结果,但是regress是首选的MATLAB方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM