Effacer les filtres
Effacer les filtres

decide the size of matrix returned by gradient function

1 vue (au cours des 30 derniers jours)
Sanjana Singh
Sanjana Singh le 27 Mai 2020
Commenté : Sanjana Singh le 27 Mai 2020
I want to find gradient of a function (x,y) in a loop and want to get a matrix of 10x10 size as the gradient matrix. I tried using - [___] = gradient(F,h) to set the distance between each point with different values of h. It doesn't seem to work and only returns a 100X100 matrix whatever I try (In the code below I get a 100x100 matrix for vfy1 and vfx1. How do I make the gradient command return only a 10X10 matrix?
Code-
x_grid = linspace(1,3,10);
y_grid = linspace(1,3,10);
for i = 1:1:length(x_grid)%rows
x = x_grid(i);
vpx_0 = 5;% initialize particle velocity in x and y directions
vpy_0 = 0;
for j = 1:1:length(y_grid) %columns
y = y_grid(j);
[vfy1,vfx1] = gradient(psi,10); % here is the gradient command
vfy= -1*vfy1;
vfx = vfx1;
vpx(i,j) = sqrt((vpx_0).^2 + 2*g(1)*x);
vpy(i,j) = -1*sqrt(vpy_0.^2 + abs(2*g(2)*y));
vpx_0 = vpx(i,j);
vpy_0 = vpy(i,j);
vfx_sum = vfx_sum + vfx;% has been pre-allocated (not shown here)
vfy_sum = vfy_sum + vfy;% has been pre allocated (not shown here)
end
end
  4 commentaires
Rik
Rik le 27 Mai 2020
As psi is a 100x100 array, so is the output of gradient. The only thing the second input does is scaling the output. If you want a 10x10, you will have to enter a 10x10 matrix or downsample the result.
Sanjana Singh
Sanjana Singh le 27 Mai 2020
Thank you, I didn't realize that. This worked!

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by