How to plot a three variable complex function

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)
Error using nargin
Argument must be either a character vector, string scalar, or a function handle.

Error in matlab.graphics.function.ImplicitFunctionSurface>getFunction

Error in matlab.graphics.function.ImplicitFunctionSurface/updateFunction

Error in matlab.graphics.function.ImplicitFunctionSurface/set.Function_I

Error in matlab.graphics.function.ImplicitFunctionSurface/set.Function

Error in matlab.graphics.function.ImplicitFunctionSurface

Error in fimplicit3>singleFimplicit (line 186)
hObj = matlab.graphics.function.ImplicitFunctionSurface(fn,extraOpts{:},args{:});

Error in fimplicit3>@(f)singleFimplicit(cax,f,limits,extraOpts,args) (line 148)
hObj = cellfun(@(f) singleFimplicit(cax,f,limits,extraOpts,args),fn,'UniformOutput',false);

Error in fimplicit3>vectorizeFimplicit (line 148)
hObj = cellfun(@(f) singleFimplicit(cax,f,limits,extraOpts,args),fn,'UniformOutput',false);

Error in fimplicit3 (line 122)
hObj = vectorizeFimplicit(cax,fn,limits,extraOpts,args);

 采纳的回答

Torsten
Torsten 2024-4-20
编辑:Torsten 2024-4-20
You cannot plot the complete result of a function that depends on three independent variables.
But you can plot it on slices (i.e. 2d-objects in (x,y,t)-space (e.g. planes)):
And plot real part and imaginary part of the function separately (using real and imag).

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by