How can I plot this code?

clc
close all
clear all
%Lenght of the plate ----------------------------------------------
lx= input ('Enter the desire value for x length:');
ly= input ('Enter the desire value for y length:');
%alpha ------------------------------------------------------------
k=143; %Thermal coductivity (W/m.C)
p=2.8*10^3; %Density (kg/m^3)
c=795; %Specific heat (J/kg.C)
alpha= k/(p*c); %Thermal diffusivity (m^2/s)
%Grid Spacing
h= input('Enter the desire grid spacing:');
while rem (lx,h)~=0 || rem (ly,h)~=0
fprintf ('Incorrect solution \n Please enter a value which results in an integer number:')
h= input ('Reenter the desire grid spacing:');
end
%Grid Spacing along lx and ly -------------------------------------
nc= (lx/h)+1; %Number of columns
nr= (ly/h)+1; %Number of raws
%Time step --------------------------------------------------------
dt= input ('Enter the desire time step:');
while dt>= h^2/(4*alpha)
fprintf('solution is unstable. Please return to dt and choose a smaller value for: %g\n', h^2/(4*alpha))
dt= input ('Enter the desire time step:');
end
%Fourier Number (fo) ----------------------------------------------
fo= alpha*dt/(h^2);
%Creation of vectors ----------------------------------------------
T1= zeros (nr, nc);
%Boundary conditions ----------------------------------------------
T1(end,:)=0;
T1(1,:)=50;
for i= 1:nr
T1(i,1)= 50-50/(nr-1)*(i-1)
T1(i,end)= 50-50/(nr-1)*(i-1)
end
%For loops for temperatura: (Ts + Tn + Tw + Te - (4-1/fo)* Tp)) * fo
T2=T1;
for t=0:dt:inf
T1=T2
for j=2:nc-1
for i=2:nr-1
T2(i,j)= (T1(i-1,j)+ T1(i+1,j)+T1(i,j+1)+T1(i,j-1)-(4-1/fo)*T1(i,j))*fo;
end
end
%check convergence
if max(max(T2-T1))<0.001
break
end
end
disp(dt*t)

9 件のコメント

Rik
Rik 2021 年 1 月 21 日
What is your question? Is the plot function what you're looking for?
Hdez
Hdez 2021 年 1 月 21 日
Yes it is. I don't know how to plot this code
Cris LaPierre
Cris LaPierre 2021 年 1 月 21 日
Ch 9 of MATLAB Onramp will introduce you to plotting in MATLAB.
Image Analyst
Image Analyst 2021 年 1 月 21 日
T2 looks like a 2-D matrix, maybe you want
imshow(T2, []);
Hdez
Hdez 2021 年 1 月 22 日
I want something that looks like this but still don't know how to do it
Rik
Rik 2021 年 1 月 22 日
Did you do the Onramp yet?
Hdez
Hdez 2021 年 1 月 22 日
I don't even know what that is?
Hdez
Hdez 2021 年 1 月 22 日
I have now but still don't know how to do it. Matlab is not my thing at all and I struggle a lot to know how to do things
Rik
Rik 2021 年 1 月 22 日
You can start out with imshow and then look into colormap and colorbar.

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

回答 (1 件)

Gaurav Garg
Gaurav Garg 2021 年 1 月 25 日

0 投票

Hi Hdez,
You can simply plot using plot command -
plot(T2)
To know more about plot command, you can refer here, or if you want to know which types of plots can be plotted in MATLAB, you can refer here.

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2021 年 1 月 21 日

回答済み:

2021 年 1 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by