Borrar filtros
Borrar filtros

how can i find the gradient of this function

3 visualizaciones (últimos 30 días)
Anar Alshanbayeva
Anar Alshanbayeva el 7 de En. de 2016
Respondida: Star Strider el 7 de En. de 2016
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;

Respuestas (1)

Star Strider
Star Strider el 7 de En. de 2016
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.)

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by