Create a 1D row vector (5,1) with middle elements = T.
1 回表示 (過去 30 日間)
古いコメントを表示
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1048200/image.jpeg)
This is my code: I have problems with assigning the variable T to the 1D row vector.
N = 3;
a1=-2;
a2 = 1;
a3 = 1;
A = diag(a1*ones(1,N)) + diag(a2*ones(1,N-1),1) + diag(a3*ones(1,N-1),-1);
b = zeros(3,1); b(1,1) = -40; b(3,1) = -20;
T=A\b;
x=linspace(0,0.8,5);
Temperature= ones(5,1); Temperature(1,1)=40; Temperature (5,1)=20;
Temperature(2:n-1)=T;
plot(x,Temperature)
title('Temperature distribution between x=0 and x=0.8 ')
xlabel('x')
ylabel('Temperature')
0 件のコメント
回答 (1 件)
Karim
2022 年 6 月 28 日
編集済み: Karim
2022 年 6 月 28 日
I guess this was only a typographical error, where you inserted the variable 'T' into 'temperature', see below for the adjusted code:
n = 100; % gridpoints
T1 = 100; % temp T1
T2 = 0; % temp T2
%construct a tridiagonal matrix
A=2*eye(n);
A=A-diag(ones(n-1,1),1);
A=A-diag(ones(n-1,1),-1);
A(1,:)=0;
A(1,1)=1; %Since the temperature at node 1 is known
A(n,:)=0;
A(n,n)=1; %Since the temperature at node n is known
% Construct a vector b with known temperatures
b=zeros(n,1);
b(1)=T1;
b(end)=T2;
x = linspace(0,0.8,n);
Temperature = A\b;
T = Temperature(2:end-1); % extract the middle temperatues for the ex
figure
plot(x,Temperature)
title('Temperature distribution between x=0 and x=0.8 ')
xlabel('x')
ylabel('Temperature')
16 件のコメント
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!