how can i find the gradient of this function

조회 수: 1 (최근 30일)
Anar Alshanbayeva
Anar Alshanbayeva 2016년 1월 7일
답변: Star Strider 2016년 1월 7일
hi everyone, I am trying to calculate the gradient of this function (in X and Y direction): Lw=sum(w(x,y) * l (x, y)); where l = (sqrt( (x(i+1)-x(i))^2-(y(i+1)-y(i))^2 ));
and what I do is for the X direction: coef=( w*(x(i+1)-x(i))/( (x(i+1)-x(i))^2+(y(i+1)-y(i))^2 ) ); Gx(i)=gwx* (sqrt( (x(i+1)-x(i))^2-(y(i+1)-y(i))^2 )) + ( w*(x(i+1)-x(i))/( (x(i+1)-x(i))^2+(y(i+1)-y(i))^2 ) ); Gx(i)=Gx(i)+coef;
For the y direction: coef2=( w*(y(i+1)-y(i))/( (x(i+1)-x(i))^2+(y(i+1)-y(i))^2 ) ); Gy(i)=gwy* (sqrt( (x(i+1)-x(i))^2-(y(i+1)-y(i))^2 )) + ( w*(y(i+1)-y(i))/( (x(i+1)-x(i))^2+(y(i+1)-y(i))^2 ) ); Gy(i)=Gx(i)+coef2;

답변 (1개)

Star Strider
Star Strider 2016년 1월 7일
I cannot follow the code in your post that you want to work with. There are Symbolic Math Toolbox functions that can calculate the gradient of a symbolic function if you want to do that.
To calculate a numerical gradient, I would start by defining the x and y ranges of values using the meshgrid function, then use the gradient function to do a numerical gradient calculation. See the documentation for those functions for the details. (Both meshgrid and gradient are core MATLAB functions so you do not need any additional Toolboxes to use them.)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by