Azzera filtri
Azzera filtri

how can i find the gradient of this function

3 visualizzazioni (ultimi 30 giorni)
Anar Alshanbayeva
Anar Alshanbayeva il 7 Gen 2016
Risposto: Star Strider il 7 Gen 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;

Risposte (1)

Star Strider
Star Strider il 7 Gen 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.)

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by