Surface Plots on randomly distributed points

조회 수: 3 (최근 30일)
Ali Baig
Ali Baig 2018년 10월 22일
편집: Stephan 2018년 10월 25일
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