필터 지우기
필터 지우기

Minimizing linear equation Ax=b using gradient descent

조회 수: 11 (최근 30일)
Tevin
Tevin 2022년 12월 20일
댓글: Tevin 2022년 12월 20일
I want to find the error in the solution to Ax=b, using gradient descent.
E=||Ax-b||^2
x = [x1;x2], where x1 and x2 range between -5 and 5, with step size 0.2 for each direction.
How do I use Gradient Descent to search for a local minimum with know step size of 0.2, learning rate= 0.1. The search should stop when the difference between previous and current value is 0.002. I am to find solution for x using Gradient Descent, as well error E.
  댓글 수: 4
Hiro Yoshino
Hiro Yoshino 2022년 12월 20일
You need to derive the derivative of the Error function. Gradient Descent requires it to move the point of interest to the next.
Tevin
Tevin 2022년 12월 20일
Thank you. The function that I wrote already does that. My problem is that I struggle to calculate error for all the grid values (X,Y). The array sizes are incompatible but I am not sure how to fix that.

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

채택된 답변

Matt J
Matt J 2022년 12월 20일
편집: Matt J 2022년 12월 20일
[X1,X2]= meshgrid(-5:0.2:5);
x=[X1(:)';X2(:)'];
E=vecnorm( A*x-b, 2,1);
E=reshape(E,size(X1)); %if desired
  댓글 수: 3
Torsten
Torsten 2022년 12월 20일
It's sqrt(sum((A*x-b).^2))
Tevin
Tevin 2022년 12월 20일
Thank you both. This really helped

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by