adding a variable into a vector

2 visualizaciones (últimos 30 días)
Ellie Matlab
Ellie Matlab el 28 de Jun. de 2022
Comentada: Ellie Matlab el 28 de Jun. de 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')

Respuestas (1)

Dyuman Joshi
Dyuman Joshi el 28 de Jun. de 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)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by