# Solving 2d heat problem using meshgrid

18 views (last 30 days)

Show older comments

##### 8 Comments

Torsten
on 4 Feb 2024

### Accepted Answer

William Rose
on 4 Feb 2024

Edited: William Rose
on 4 Feb 2024

@Ali,

[edit: fix spelling erors]

A 10x10 mesh for this problem is so few points that it makes it hard to set up the problem and get reasonable results. I am going to make it with more points. You can adjust if you like.

One simple-minded way to do this is to create a 3D rectangular array. The third dimension is for time. You can adjust the time duration if you don't like the results.

x=-10.5:1:10.5; % x-coordinates of the grid points

y=x; % y-coordinates of the grid points

dt=0.5; % time step size

t=0:dt:100; % time values

Tout=130; % external temperature

T=Tout*ones(length(x),length(y),length(t)); % array for temperature

You will want to use a simple first-order difference equation to update the temperature at each time step.

You will need to initialize the temperature at t=0 so that it is 40 inside the square and 10 in the green area.

You will use a set of nested for loops to do this. The outer loop is time, the inner loops are x and y (order of the inner loops not important, as long as you check all the grid points).

At each time step, you will update the temperature at all the grid points, using the tepratures at the previous time step. Points inside the inner square, and points outside the circle, will not change with time. Points in the green area will change with each new time step, accortding to the difference equation which you will develop.

The difference equation will look somethink like this:

T(i,j,k)=T(i,j,k-1)+...

where k is the time index, and you should figure out what the "..." is.

##### 3 Comments

William Rose
on 5 Feb 2024

@Ali, You are weelcome.

Here is a discussion of a similar problem. I am not endorsing the code by the original poster. That problem has 3 spatial dimensions. Array T in that problem is T(m,i,j,k), where index m is for time. That problem does not have an inner cut-out. The graphical display of results for that problem may be useful for you.

### More Answers (0)

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!