matlab绘制三维图

问题遇到的现象和发生背景

如何让这个方程表示三维图

问题相关代码,请勿粘贴截图

w(x,t)=2*(x,t-1)-w(x,t-2)+ dt^2*(T*(w(x+1,t-1)-2w(x-1,t-1))/dx^2)/p;

运行结果及报错内容

clc;clear all
syms x t n z;
h=0.01;
L=10;
T=10;
p=0.1;
Ms=1;
x=0:h:L;(表示x的范围)
t=0:1:20;(t的范围 表达好像不对 )
f(x,t)=(3+sin(pixt)+sin(2pixt)+sin(3pixt))x/1000;
w(x,t)=2
(x,t-1)-w(x,t-2)+ dt^2*(T*(w(x+1,t-1)-2w(x-1,t-1))/dx^2+f(x,t-1))/p;
z=w(x,t);

我的解答思路和尝试过的方法

怎么解决

我想要达到的结果

呈现一个三维图

同学你做的是偏微分方程的数值解,给你一个热传导方程实现的代码,自己看看怎么求解就行:

%
% This code solves the steady 1D diffuion equation using FDM for the
% unknown Temperature. Analytical solution comparison is done with
% Numerical. Example # 2 on Versteeg 2E book Pages 135-139
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
close;
clc
%% Sort out Inputs
tic
% Number of Control Volumes
N = 5;
% Domain length
L = 0.02; %[m]
% Grid Spacing
h = L/(N);
% Diffusivity (Thermal conductivity)
k = 0.5;  %[W/m-K]
% Uniform Heat Generation, A Source Term
q = 1000e3;     %  [W/m^(3)]
% The center of the first cell is at dx/2 & the last cell is at L-dx/2.
x = h/2 : h : L-(h/2);
% Cross sectional area of the 1D domain
A = 1;          %[m^2]
% Left Boundary Condition
T_a = 100;    %[\circ c]
% Right Boundary Condition
T_b = 200;    %[\circ c]
% Initialising Temperature
Nh = 2*N + 1; % the  number of node with temperature
T=zeros(Nh,1);
% Left Boundary Condition
T(1)= T_a;    %[\circ c]
% Right Boundary Condition
T(Nh) = T_b;    %[\circ c]
% Interior of Domain
index_x = 2:Nh-1;
%% Formation of Coefficient Matrices, Numerical Solution
% Tolerence
eps = 1.e-6;
% Iteration
It = 0;
T_old = T;
Error = 2*eps;
% Calculation
while   (Error > eps)
    It = It +1;
    T(index_x)= 0.5*(T(index_x-1) + T(index_x+1)+ (q*h*h/4)/(k)); % here divided by 4, cause h/2*h/2
    Error = max(abs(T(:)-T_old(:)));
    if any(isnan(T(:))) || any(isinf(T(:)))
        fprintf(' Iteration Diverge \n');
        return;
    end
    T_old = T;
end
T_Numeric = T(2:2:end);
%% Analytical Results
X_G = x;
T_Analytical=((T_b-T_a)/L + (q/(2*k))*( L - X_G )).*(X_G) + T_a;%解析解
%% Error Analysis
M_Error(N)=0;
for i=1:N
    % This x is only use to compare results on Versteeg book
    k=find(abs(X_G - x(i))<=1e-3);
    % No need to find k (You can but no Need)
    % Absolute Error
    M_Error(i) = abs(T_Numeric(i)-T_Analytical(i));
    % Relative Error
    Relative_Error(i) = abs(T_Numeric(i)-T_Analytical(i))/abs(T_Numeric(i));
    % Percentage Error
    Percentage_Error(i) = Relative_Error(i).*100;
end
%% Post Processing
% Data Table Comparison of Different Results
Nodes = 1 : N;
fprintf('Node\tGrid_{Loc.}\t\tT_{Num.}\t\tT_{An.}\t\tError\n\n');
fprintf('===\t\t=======\t\t=========\t\t=========\t\t=======\n');
for i = 1: N;
    fprintf('%3.0f\t\t%3.5f\t\t%3.5f\t\t%3.5f\t\t%3.5f\n',[Nodes(i); X_G(i); T_Numeric(i); T_Analytical(i); Percentage_Error(i)]);
end
% Graphical Representation
plot(100*x,T_Numeric,'-o','MarkerSize',5,'MarkerFaceColor','b');
% hold on
% plot([0, 100.*L], [T_a, T_b], 'd', 'LineWidth',3,'MarkerFaceColor','b');
hold on
plot(100*X_G,T_Analytical,'r--','LineWidth',2);
% hold on
% plot([0, 100.*L], [T_a, T_b], 'd', 'LineWidth',3,'MarkerFaceColor','r');
% xlim([0  2]);
% ylim([50 300]);
%Boundary Points Inclusion
xlabel('Distance (m)');
ylabel('Temperature [\circ C]');
legend('T_{Numeric}','T_{Analytical}');
title ('Numerical & Analytical Results Comparison');
grid on;