Surface Plots on randomly distributed points

3 views (last 30 days)
Ali Baig
Ali Baig on 22 Oct 2018
Edited: Stephan on 25 Oct 2018
Dear All,
I am trying to plot a 2D function z=f(x,y) on randomly distributed points using surf command. The code I have written is given below
clear all
close all
clc
N = 1600
X = rand(N, 1); Y = rand(N, 1);
Pe = 1000;
T_exact = zeros(N, 1);
a = (Pe + sqrt(4*pi^2+Pe^2))/2;
b = (Pe - sqrt(4*pi^2+Pe^2))/2;
T_exact = sin(pi * Y) .* (exp(b * X) - exp(a * (X - 1) + b))/(1-exp(b - a));
X_t = vec2mat(X, sqrt(N)); Y_t = vec2mat(Y, sqrt(N));
T_exact_t = vec2mat(T_exact, sqrt(N));
exact_Solution = surf(X_t, Y_t, T_exact_t);
xlabel('\rightarrow X'), ylabel('\rightarrow Y'), zlabel('\rightarrow T'), grid on, colorbar
set(gca,'fontsize', 15)
set(findall(gca, 'Type', 'Line'),'LineWidth',2);
The graph is not smooth. Can anyone tell me what should I do?

Answers (1)

Stephan
Stephan on 22 Oct 2018
Edited: Stephan on 22 Oct 2018
Hi,
consider the following small example:
N = 10;
X = rand(N, 1);
Y = rand(N, 1);
Z = X*Y';
surf(X, Y, Z);
results in:
.
Now try:
N = 10
X = sort(rand(N, 1));
Y = sort(rand(N, 1));
Z = X*Y';
surf(X, Y, Z);
which results in:
.
Check your code and think about what can be sorted (without creating meaningless calculations!) - then you should get a better result
Best regards
Stephan
  2 Comments
Ali Baig
Ali Baig on 25 Oct 2018
Dear Stephen,
I have attempted in quite a number of different ways, but I am not getting the right plot.
Stephan
Stephan on 25 Oct 2018
Edited: Stephan on 25 Oct 2018
i dont have access to vec2mat function, since i do not have the Communications Toolbox - please load up a .mat-file containing these values
X_t
Y_t
T_exact_t
Could you also explain why you change X (1600x1) to X_t (40x40)?
i guess you should do something like this:
N = 49 % Do not use 1600...
X = sort(rand(N, 1));
Y = sort(rand(N, 1));
[m,n] = meshgrid(1:numel(X),1:numel(Y));
Pe = 1000;
T_exact = zeros(N, 1);
a = (Pe + sqrt(4*pi^2+Pe^2))/2;
b = (Pe - sqrt(4*pi^2+Pe^2))/2;
T_exact = sin(pi .* Y(n)) .* (exp(b .* X(m)) - exp(a .* (X(m) - 1) + b))./(1-exp(b - a));
surf(X, Y, T_exact);
which gives:

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!