Help with MatLab/C++ Loops (Heat Transfer, Matrices)

Click For Summary
SUMMARY

This discussion focuses on solving a transient heat transfer conduction problem using MATLAB or C++. The user has a 12x12 coefficient matrix [A] and a 12x1 answer matrix [C], with the goal of iteratively calculating a new matrix [B] for each time step. The solution involves using matrix inversion, specifically the MATLAB syntax B = A\C for efficiency. A loop structure is necessary to update the values in matrix [C] for each time step, allowing for the calculation of subsequent matrices [B].

PREREQUISITES
  • Understanding of transient heat transfer concepts
  • Familiarity with MATLAB syntax and matrix operations
  • Knowledge of matrix inversion techniques
  • Basic programming skills for implementing loops
NEXT STEPS
  • Learn MATLAB matrix manipulation techniques
  • Explore advanced MATLAB loop structures for iterative calculations
  • Study numerical methods for solving heat transfer equations
  • Investigate C++ libraries for matrix operations, such as Eigen
USEFUL FOR

Engineers, researchers, and students working on heat transfer problems, as well as programmers looking to implement numerical solutions in MATLAB or C++.

tectactoe
Messages
38
Reaction score
0
Basically, I need to solve a transient heat transfer conduction problem. I've got most of the work done but I need to solve the problem using MATLAB or C++ or some other kind of coding. That's what I need help with.

The actual aspects of the problem aren't really that important, so I will try to explain the part I need help with, without getting into too much detail.

I have a 12x12 matrix, we will call it [A]. This matrix contains coefficients for a series of equations that contain variables T_{n}^{i+1}, from n = 1 to 12. Then we have the answer matrix, we'll call matrix [C] which is a 12x1 matrix with values T_{n}^{i}, also from n = 1 to 12. Initially, at t=0, T_{n}^{i} = 0 for all n.

We then solve for matrix which contains the variables of which [A] holds the coefficients of, as mentioned before, T_{n}^{i+1}.

This can be easily done by <b> = [A]^{-1}[C]</b>

Then matrix will hold all my answers for T_{n}^{i+1} from n = 1 to 12.

Now my problem is, for the next time step, say t = 1s, I need to use the answers held in matrix and essentially plug those values in for the previous values held in matrix [C], and repeat the calculation for a new matrix after 1s. Then, I take those new values and sub those into the [C] matrix again and get yet another new matrix for 2s. I need to do this for very many time steps, so I know a loop must be used.

The problem is, I am awful with coding and don't know how this can be done.

Any help would be appreciated. If you are having trouble understanding my question, please ask and I will clarify.

Thank you!
 
Physics news on Phys.org
It seems you want a discrete time solution of an equation solvable by <b> = [A]^{-1}[C]</b>.

The loop you would need in MATLAB would look as such

Code:
% hint: MATLAB allows inverse to be performed as either 
% inv(A)*C or A\C the latter performs much faster. I will use the latter

%start program
Bo = A\Co %initial conditions at t=0
Cn(1) = Bo %stores your old answer in the new C

for i = 1:t

    %solves for current B vector using the new C matrix from time step i
    B(i) = A\Cn(i)

   %stores your old answer in the new C matrix for time step i+1
   Cn(i+1) = B(i)

end %end iteration

You can try something like that. And of course you need to initialize your matrices properly.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
22
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 23 ·
Replies
23
Views
9K
Replies
6
Views
3K