Function with matrix input arguments

Hi, I want to evaluate the following equation
F=((sqrt(2)/(81*sqrt(pi)))*(6*R-R^2)*exp(-R/3)*cos(TH))^2;
Both R and TH are matrices. How can I make sure that F can handle matrix inputs?
I later want to plot this function using:
[X,Y] = pol2cart(TH,R)
surf(X,Y,F)

回答 (2 件)

KSSV
KSSV 2016 年 11 月 7 日

0 投票

r = linspace(0,1) ;
th = linspace(0,2*pi) ;
[R,TH] = meshgrid(r,th) ;
F=((sqrt(2)/(81*sqrt(pi)))*(6*R-R^2)*exp(-R/3)*cos(TH))^2;
[X,Y] = pol2cart(TH,R) ;
surf(X,Y,F)
Walter Roberson
Walter Roberson 2016 年 11 月 7 日

0 投票

Vectorize.
F = ((sqrt(2) ./ (81*sqrt(pi))) .* (6*R-R.^2) .* exp(-R/3) .* cos(TH)).^2;

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

質問済み:

2016 年 11 月 7 日

回答済み:

2016 年 11 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by