Gradient function not matching array dimensions

9 ビュー (過去 30 日間)
Carlos Martinez
Carlos Martinez 2023 年 3 月 16 日
コメント済み: Matt J 2023 年 3 月 16 日
I have the function
psi=y+atan2(y,x)*0.5/pi;
which is classified as a 51x51 double for its value. How would I take the gradient of x and y for this function?

採用された回答

Matt J
Matt J 2023 年 3 月 16 日
Alternatively, why not use the gradient command?
psi =rand(51);
[gradx,grady]=gradient(psi);
whos psi gradx grady
Name Size Bytes Class Attributes gradx 51x51 20808 double grady 51x51 20808 double psi 51x51 20808 double

その他の回答 (1 件)

Matt J
Matt J 2023 年 3 月 16 日
The expression for the gradient is very simple. Why not just apply the analytical expression on whatever meshgrid you are working with?
syms x y real
syms psi
psi=y+atan2(y,x)/2/pi;
g=simplify(gradient(psi))
g = 
  2 件のコメント
Carlos Martinez
Carlos Martinez 2023 年 3 月 16 日
Thanks! Is there a way to separate the components for it? I'm trying to get the u and v values for the stream function
Matt J
Matt J 2023 年 3 月 16 日
Perhaps as follows?
function [Gx,Gy]=mygrad(X,Y)
den=2*pi*(X.^2+Y.^2);
Gx=-Y./den;
Gy=X./den+1;
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by