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

 Risposta accettata

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 Commenti

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Centro assistenza e File Exchange

Prodotti

Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by