For Loop through Matrix
이전 댓글 표시
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
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
2022년 5월 2일
Torsten
2022년 5월 2일
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
2022년 5월 2일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
