adding a variable into a vector

2 vues (au cours des 30 derniers jours)
Ellie Matlab
Ellie Matlab le 28 Juin 2022
Commenté : Ellie Matlab le 28 Juin 2022
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')

Réponses (1)

Dyuman Joshi
Dyuman Joshi le 28 Juin 2022
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 commentaire
Ellie Matlab
Ellie Matlab le 28 Juin 2022
ah! got it. thanks!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by