How to plot a three variable complex function
Show older comments
I want to plot two functions : the first one is the exact solution of a 2D time dependent PDE, and the second one is the solution of the PDE using the finite difference method.
I tried using fimlicit3() but an error message is showing also the plot is empty.
clc ; clear all ; close all ;
% 2D time dependent linear PDE in the domain [0 , l ] x [0 , l ]
% iut = -( uxx + uyy) + u
% Initial condition u(x,y,0) = phi(x,y)
% Boundary conditions u(0,0,t) = u(0,0,l) = 0
% Approximate solution by using explicit FDS
N = 4; % space discretization
P = 9; % time discretization
l = pi; % the space interval [0,l]x[0,1]
T = 1; % the time interval [0,T]
h = l/(N+1); % the space step (I used the same step for x and y)
k = T/(P+1); % the time step
alpha = k/(h^2); % alpha and beta are coeficients used in the FD scheme
beta= 1-4*alpha-complex(0 ,1)*k;
%----The function phi(x,y)--------
phi=@(x,y) sin(10*x)*sin(4*y);
for r = 1:N+1
for s = 1:N+1
phirs(r,s) = phi((r-1)*h,(s-1)*h);
end
end
%---------The function u---------
u = zeros(N+1,N+1,P+1);
%------Boundary connditions-----
for r = 1:N+1
for s = 1:N+1
u(r,s,1) = phirs(r,s);
end
end
u(1,1,1:P+1) = 0;
u(N+1,N+1,1:P+1) = 0;
%-------Finding u(i,j,n)------
for n = 1:P
for i = 2:N
for j = 2:N
u(i,j,n+1)= beta*u(i,j,n) + alpha*(u(i+1,j,n)+u(i-1,j,n)+u(i,j+1,n)+u(i,j-1,n));
end
end
end
%----The exact solution ----
f = @(x,y,t) exp(complex(0,1)*t)*sin(10*x)*sin(4*y);
%----The plot ------
t=linspace(0,1,1/10);
x=linspace(0,pi,1/5);
y=linspace(0,pi,1/5);
f = @(x,y,t) exp(complex(0,1)*t)*sin(10*x)*sin(4*y);
fimplicit3(u)
Accepted Answer
More Answers (0)
Categories
Find more on Geometry and Mesh 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!