adding a variable into a vector
2 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
回答(1 个)
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)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!