Surface Plots on randomly distributed points

3 次查看(过去 30 天)
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?

回答(1 个)

Stephan
Stephan 2018-10-22
编辑:Stephan 2018-10-22
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 个评论
Ali Baig
Ali Baig 2018-10-25
Dear Stephen,
I have attempted in quite a number of different ways, but I am not getting the right plot.
Stephan
Stephan 2018-10-25
编辑:Stephan 2018-10-25
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:

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by