Difference in plots obtained from fsurf and surf command
11 views (last 30 days)
Show older comments
Nikhil Yewale
on 18 Aug 2020
Commented: Gangala
on 1 Dec 2022
Hello,
I would be glad if anyone points out why fsurf and surf command show different plots(attached with this question) for the following function that I wish to visualize:
in defined in region and
Following is the my MATLAB script for plotting using fsurf and surf command. Plot obtained using surf matches correctly with the one obtained from wolfram mathematica, whereas one obtained from fsurf is unable to plot values near the corner of domain i.e. near [10,10]
Attachments- using_mathematica.png
using_fsurf.png
using_surf.png
close all;
C = 1/9;
%% need to visualize following function in [0 10] square domain
K = @(X,Y) sqrt(Y).*(X.^(3/2)).*exp(-C.*(X.^3 + Y.^3)).*...
besseli(1/3,(2/9).*(X.^(3/2)).*(Y.^(3/2)));
%% plot using fsurf
figure(1)
fsurf(K,[0 10 0 10])
xlabel('X')
ylabel('Y')
zlabel('K')
title('Plot using fsurf')
%% plot using surf
[X,Y] = meshgrid(0:0.1:10);
figure(2)
surf(X,Y,K(X,Y))
xlabel('X')
ylabel('Y')
title('Plot using surf')
zlabel('K')
Accepted Answer
Srivardhan Gadila
on 22 Aug 2020
As per my knowledge, I think the difference is due to the overflow of besseli function and the implementation of the fsurf function.
You can experiment with the below code:
close all;
C = 1/9;
%% need to visualize following function in [0 10] square domain
% K = @(X,Y) sqrt(Y).*(X.^(3/2)).*exp(-C.*(X.^3 + Y.^3)).*...
% besseli(1/3,(2/9).*(X.^(3/2)).*(Y.^(3/2)));
K1 = @(X,Y) sqrt(Y).*(X.^(3/2)).*exp(-C.*(X.^3 + Y.^3));
K2 = @(X,Y) besseli(1/3,(2/9).*(X.^(3/2)).*(Y.^(3/2)));
K = @(X,Y) K1(X,Y).*K2(X,Y);
%% plot using fsurf
figure(1)
subplot(2,3,1); fs = fsurf(K1,[0 10],'MeshDensity',100);
subplot(2,3,2); fs = fsurf(K2,[0 10],'MeshDensity',100);
subplot(2,3,3); fs = fsurf(K,[0 10],'MeshDensity',100);
xlabel('X')
ylabel('Y')
zlabel('K')
title('Plot using fsurf')
%% plot using surf
[X,Y] = meshgrid(0:0.1:10);
subplot(2,3,4); surf(X,Y,K1(X,Y));
subplot(2,3,5); surf(X,Y,K2(X,Y));
subplot(2,3,6); surf(X,Y,K(X,Y));
xlabel('X')
ylabel('Y')
title('Plot using surf')
zlabel('K')
I have split the original function into two functions K1 & K2, where K2 is the besseli function, In the below plots you can observe the overflow
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!