How can i write this in Matlab?
2 次查看(过去 30 天)
显示 更早的评论
1 个评论
Walter Roberson
2020-3-28
The summation can be split to and each of those Σ can be translated into a sum() call.
With a small bit of cleverness you can also replace two of the sums with var() calls.
回答(1 个)
Ameer Hamza
2020-3-28
编辑:Ameer Hamza
2020-3-28
If x and y are 1D vectors then try something like this.
x = rand(100, 1);
y = rand(100, 1);
x_bar = mean(x);
y_bar = mean(y);
b_hat = sum(x-x_bar)*sum(y-y_bar)/sum((x-x_bar).^2);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!