Heat transfer in a square using Matlab

A university professor asked us to solve the heat transfer in a square with predetermined boundary conditions using Matlab. As a fan of programming I took it upon myself to write a generalized script that allows flexibility in the boundary conditions.

Although Matlab is a commercial proprietary software, I have decided to include this project in the programming section since it does not use much of the higher functions of the software and can technically be reproduced in any programming language without significant difficulty.

After writing down the solution and the underlying formulas, it came to my attention that the equation for implementing the three usual boundary conditions, namely constant temperature, convection and no heat transfer are quite similar and can, in fact, be applied by choosing an appropriate convective heat coefficient. That means, by entering a high enough coefficient a wall will have constant temperature and by selecting 0 for the term, there will, obviously, be no exchange with the outside.

Utilizing this principle and solving the problem with named variables instead of the values given in the question, made the script capable of solving a variety of heat transfer cases, garnering me the highest grade of the class for the project. That being said, the script is still limited to an square shape and cannot solve for constant flux. Another downside of the code is the high runtime, especially for bigger planes and finer meshes.

The code is available on Github and also for download from the link below. I would love to get some feedback on it, particularly about how to optimize it in order to reduce runtime. Contact me if you want to share your thoughts or if there is anything I can help you with.

Leave a comment

Design a site like this with WordPress.com
Get started