Plotting 3 variables error

17 ビュー (過去 30 日間)
Luke
Luke 2018 年 4 月 1 日
コメント済み: Luke 2018 年 4 月 1 日
Hi, I have been trying to plot the following code without success. I have tried pcolor, contour, mesh and surf. Would appreciate any help.
%%Parameters
L = 50e-5; %m
alpha0 = 3.71e-3; %m^2/s
Q = 137653.6;
R = 8.314;
Tm = 0; %C
Ttop = 0; %C
tmax = 3.71e-3; % in seconds !!
T0 = 473.15;
t1 = (1:11);
r = 10;
Te = T0-r.*t1;
%%Discretisation
Dx = 50e-6;
Dtmax = 0.5*Dx^2/alpha0;
Dt = 0.5*Dtmax;
%time vector:
t = 0:Dt:tmax;
%space vector:
x = 0:Dx:L;
%number of nodes in time and space
N = length(t);
I = length(x);
%%initialisation
T = zeros(N,I);
%initial conditions:
T(1,:) = Tm;
T(1,1) = Ttop;
%%iterations
for n=1:N-1
%boundary conditions:
T(n+1, 1) = Ttop;
T(n+1, I) = Tm;
%interior points:
for in=2:I-1
a_ip = 0.5*(alpha0*exp(-(Q./R*Te(in+1))+ alpha0*exp(-(Q./R.*Te(in)))));%this is where the error lies
a_im = 0.5*(alpha0*exp(-(Q./R.*Te(in))+ alpha0*exp(-(Q./R.*Te(in-1))))) ;
T(n+1, in) = T(n, in) + (Dt/Dx^2)*(a_ip*(T(n,in+1) - T(n,in)) -...
a_im*(T(n,in) - T(n,in-1)));
end
end
%%plots
%plots
figure;
surf(x,t1,Te');
xlabel('x (m)');
ylabel('t (s)');

採用された回答

Birdman
Birdman 2018 年 4 月 1 日
編集済み: Birdman 2018 年 4 月 1 日
Replace
figure;
surf(x,t1,Te');
with
[X,T1]=meshgrid(x,t1);
Te=X+T1; %this is randomly selected function, you can change it.
figure;
surf(X,T1,Te);
  3 件のコメント
Birdman
Birdman 2018 年 4 月 1 日
Yes. Try this:
contour(X,T1,Te)
Luke
Luke 2018 年 4 月 1 日
Thanks birdman

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by