Function that should be continuous isn't continuously plotted?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Niklas Kurz
am 3 Dez. 2020
Bearbeitet: Daniel Pollard
am 3 Dez. 2020
Given the function: f(x,y) = (x^3 - 3*x*y^2)/(x^2+y^2)
I'd plot it typing:
[x,y] = meshgrid(-2:0.2:2)
z = (x.^3 - 3.*x.*y.^2)./(x.^2+y.^2)
surf(x,y,z)
Doing this Matlab shows me a quite dedicate plot, however with a whole in the origin (A sign for non continous functions, right?). That's why this is staying in contrast to my math lectures. Maybe it's because I haven't defined "f(x,y) = 0 if (x,y) = (0,0)". Or why is that?
0 Kommentare
Akzeptierte Antwort
Alan Stevens
am 3 Dez. 2020
The function is continuous at (0,0); it has a removable singularity. Try using
[x,y] = meshgrid(-2+eps:0.2:2+eps);
eps is Matlab's inbuilt value (about 2.2204e-16).
0 Kommentare
Weitere Antworten (1)
Daniel Pollard
am 3 Dez. 2020
Bearbeitet: Daniel Pollard
am 3 Dez. 2020
At the origin, x and y are both zero, so the denominator of your function is undefined. For me it's returning NaN at the central point:
>> z(11, 11)
ans =
NaN.
Edit as I realise I failed to actually address the issue. As far as I can tell there are two options:
- Make the vector steps smaller, so instead of meshgrid(-2:0.2:2), you could use meshgrid(-2:0.05:2), which would make the plot appear more continuous and make the "hole" in the middle smaller, and nearly invisible.
- Set the NaN value to zero. This is as simple as adding the line
z(isnan(z))=0;.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!