For Loop through Matrix
Show older comments
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 Comments
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
on 2 May 2022
Torsten
on 2 May 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
on 2 May 2022
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!