Incorrect 3d graph of Complex Function (with Singular Matrix Error)

Hi,
I need to plot complex functions with x and y representing real and imaginary parts of the number, the z axis representing the value of my function.
I am using surfc for this but end up getting an obscure graph, along with the warning: matrix is close to singular or badly scaled.
The method I am using works perfectly for something simple like just plotting abs(z) but not for (e^z)/(z-2).
How can I resolve this?
My code is attached below. (I am using matlab online)
Any help would be greatly appreciated. Thanks in advance!
a = -500:10:500;
b = -500:10:500;
[A,B] = meshgrid(a,b);
z = A + 1i*B;
f = (exp(z))/(z-2)
surfc(a,b,abs(f))

 採用された回答

Star Strider
Star Strider 2022 年 4 月 20 日
Use element-wise division —
f = (exp(z))./(z-2);
a = -500:10:500;
b = -500:10:500;
[A,B] = meshgrid(a,b);
z = A + 1i*B;
f = (exp(z))./(z-2);
surfc(a,b,abs(f))
shading('interp')
.

2 件のコメント

Aditya B
Aditya B 2022 年 4 月 20 日
I have been stuck here for 2 days. Feel stupid to realise that this was what I was missing.
Thank you so much!
Star Strider
Star Strider 2022 年 4 月 20 日
As always, my pleasure!
Definitely not stupid! If it makes you feel any better, not using element-wise division is the most frequent problem I see here on Answers.
.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

製品

リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by