Help with Central Difference Code

2 views (last 30 days)
Claire
Claire on 11 Dec 2017
Answered: John D'Errico on 11 Dec 2017

I am trying to create a code to solve for the heat transfer through an exhaust system. I have inserted a picture below of a similar simplified problem. Mainly, I need help with the iterations in the 4 boxes where it says Node 1, Node 2, Node 3, and Node 4. I need to start the iterations with putting in the temperature for T0 and have the iterations end when it reaches Tn. If possible, I need the output of the temperatures (340, 40, 40, 440) to be in the form of a vector. I also need to extract the coefficients attached to T1, T2, T3, and T4 from each set of equations and put those in the form of a matrix. The very bottom of the picture shows what information is needed. This example is quite a bit simplified and is easy to do by hand. However, for the real problem I am doing, I will be working with matrices that are 250x250, 500x500, 1000x1000, etc and it will be too tedious to do all of that by hand. I would greatly appreciate any help in setting up a code. Thank you in advance!

Answers (1)

John D'Errico
John D'Errico on 11 Dec 2017
You need to learn to use MATLAB, creating arrays programmatically.
So just write a loop that creates those coefficients on the fly. Preallocate your matrix of course. Better yet, create the coefficients as a vector of coefficients, then use tools like spdiags to create the matrix.

Categories

Find more on Mathematics and Optimization 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!