Ts is changing over time. I need to get Ts to change in matrix T. How do I get it to change with each iteration within the matrix T?
clear all;clc
%Given
x=0:0.25:1; %thickness [m]
rho=2300; %density [kg/m^3]
k=1.4; %Thermal conductivity [W/mK]
c=880; %thermal coeff [J/kgK]
t=[2 11 45]*3600; %time [s]
%let
deltax=1/4;
deltat=1;
a=k/deltax;
b=(rho*deltax*c)/deltat;
%Initial conditions
Tx=300+400.*(x./2)-400*(x./2).^2;
%Solve for T'
for k=1:length(x)
for i=1:length(t)
if i<=10*3600
Ts=300+10/3600*i;
elseif i>10*3600 && i<=25*3600
Ts=400-5/3600*(i-10*3600);
else
Ts=325;
end
%Create matrices
A=1/b*[(-2*a+b) a 0 0;
a (-2*a+b) a 0;
0 a (-2*a+b) a;
0 0 a (-2*a+b)];
T=[Tx(1); Tx(2); Tx(3); Ts];
% Solve for B
B=A*T;
end
end

4 commentaires

Jan
Jan le 2 Mai 2022
Modifié(e) : Jan le 2 Mai 2022
In your code t has 3 elements. Then the loop:
for i=1:length(t)
runs for i=1, i=2, i=3. In all these cases, the first branch of the IF-condition is met:
if i<=10*3600
I assume, you want something else, maybe:
if t(i) <= 36000
I do not understand the actual problem - what does this mean: "I need to get Ts to change in matrix T".
Brittany Burns
Brittany Burns le 2 Mai 2022
Ts is a boundary condition that changes over time. I need it in order to solve for Ts in matrix T.
Torsten
Torsten le 2 Mai 2022
Your T vector has only 4 elements, but your x vector has 5.
Further, T is the vector of unknown - thus B = A*T does not make sense.
What is the differential equation together with the boundary conditions you are trying to solve ?
Brittany Burns
Brittany Burns le 2 Mai 2022
I'm trying to solve for T' on the RHS

Connectez-vous pour commenter.

 Réponse acceptée

Torsten
Torsten le 2 Mai 2022
Modifié(e) : Torsten le 3 Mai 2022

1 vote

rho=2300; %density [kg/m^3]
k=1.4; %Thermal conductivity [W/mK]
c=880; %thermal coeff [J/kgK]
xstart = 0.0;
xend = 1.0;
nx = 100;
dx = (xend-xstart)/(nx-1);
x = xstart:dx:xend;
tstart = 0.0;
tend = 45*3600;
dt = 0.5*dx^2*rho*c/k;
nt = ceil((tend-tstart)/dt);
t = linspace(tstart,tend,nt);
T0 = Tinit(x);
T = zeros(nt,nx);
T(1,:) = T0;
for j = 1:nt-1
Ts = Texternal(t(j+1)/3600);
T(j+1,1) = Ts;
T(j+1,2:nx-1) = T(j,2:nx-1) + dt*k/(rho*c)*(T(j,3:nx)-2*T(j,2:nx-1)+T(j,1:nx-2))/dx^2;
Tnxp1 = T(j,nx-1);
T(j+1,nx) = T(j,nx) + dt*k/(rho*c)*(T(j,nx-1)-2*T(j,nx)+Tnxp1)/dx^2;
end
to = [2 11 45]*3600;
it = arrayfun(@(tout)find(t-tout>=0,1,'first'),to);
plot(x,[T(it(1),:);T(it(2),:);T(it(3),:)])
function Ts = Texternal(t)
if t <= 10
Ts = 300 + 10*t;
elseif t > 10 && t <= 25
Ts = 400 - 5*(t-10);
else
Ts = 325;
end
end
function T0 = Tinit(x)
T0 = 300 + 400.*(x./2) - 400*(x./2).^2;
end

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Produits

Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by