adding a variable into a vector

2 ビュー (過去 30 日間)
Ellie Matlab
Ellie Matlab 2022 年 6 月 28 日
コメント済み: Ellie Matlab 2022 年 6 月 28 日
I need to add extra variable to my matrix b, but when i added and ran the codes, there is an error as it does not fulfil the requirements. From what i understand, i have already declared the gridpoints, L, w and k.
N = 3;
a1 =-2;
a2 = 1;
a3 = 1;
w=200000;
k=80.2;
deltax= 0.8/5-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-(w/k)*deltax^2; b(3,1) = -20-(w/k)*deltax^2; b(2,1)=-(w/k)*deltax^2;
T=A\b;
x=linspace(0,0.8,5);
Temperature = ones(1,5);
Temperature(1,1)=40;
Temperature(1,5)=20;
Temperature(2:end-1)=T;
plot(x,Temperature)
title('Temperature distribution between x=0 and x=0.8 ')
xlabel('x')
ylabel('Temperature')

回答 (1 件)

Dyuman Joshi
Dyuman Joshi 2022 年 6 月 28 日
Your deltax is incorrectly defined and due it all subsequent calculations are incorrect as well.
%It should be
L=0.8;
gridpoints=5;
deltax = L/(gridpoints-1) %=0.8/(5-1)
  1 件のコメント
Ellie Matlab
Ellie Matlab 2022 年 6 月 28 日
ah! got it. thanks!

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

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by