Least_mean Squares

조회 수: 3 (최근 30일)
Jason Earls
Jason Earls 2021년 3월 27일
댓글: Star Strider 2021년 3월 30일
I am trying to write the below function.
for(ct = 1:N )
sum_xy = sum_xy + x(ct)*y(ct) ;
sum_xx = sum_xx + x(ct)*x(ct) ;
sum_x= sum_x+x(ct)
sum_y = sum_y+y(ct)
end
% Compute best value of b
%b_tilde = sum_xy / sum_xx ;
b_tilde = (sum_xy - ((1/N)*sum_x*sum_y))/(sum_xx-((1/N)*sum_xx));
fprintf(1,'b_tilde is %1.10f \n',b_tilde) ;
I havent done a_tilde yet but i presume its (sum_y/N) - b_tilde*(sum_x/N)
any advice appreciated.

답변 (1개)

Star Strider
Star Strider 2021년 3월 27일
To make your code simpler and more efficient use the sum and mean functions. You can likely avoid the (explicit) loops.
Since you will likely need to do element-wise multiplication, also see Array vs.Matrix Operations.
  댓글 수: 2
Jason Earls
Jason Earls 2021년 3월 30일
yes because I dont know if i am writing out the above equation correctly
Star Strider
Star Strider 2021년 3월 30일
The way to test that is to produce some data with a known slope and intercept, and see if your code reproduces those parameters.
Meanwhile use the sum and mean functions to make your ocde easier to write and execute.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by