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))

 Réponse acceptée

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 commentaires

I have been stuck here for 2 days. Feel stupid to realise that this was what I was missing.
Thank you so much!
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.
.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Produits

Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by