contour function to show temperature on a 2d plate at 0, 1, 2, 5, 10, 100 seconds for discretised pde with jacobi solver in matlab

Assuming you have already implemented the Jacobi solver for a discretized PDE in Matlab, you can obtain the temperature values for each point in the 2D plate for different time steps. To visualize the temperature distribution at different time steps, you can use contour plots. Here's how you can do it:

  1. First, define the time points for which you want to see the contour plots. For example, you can define:
main.m
t = [0, 1, 2, 5, 10, 100];
27 chars
2 lines
  1. For each time point, compute the temperature values for each point in the 2D plate using the Jacobi solver. Store the temperature values in a matrix. For example, for the first time point, you can do:
main.m
% Run Jacobi solver for 100 iterations
for i = 1:100
  % Update temperature values using Jacobi iteration
  % ...
end

% Store the temperature values in a matrix T
T(:,:,1) = ... % temperature values for time 0
211 chars
9 lines

Similarly, you can compute the temperature values for other time points and store them in the matrix T.

  1. To visualize the temperature distribution at each time point, you can use contour plots. For example, to create a contour plot for the temperature values at time t=2, you can do:
main.m
contour(T(:,:,3));
19 chars
2 lines

Here, T(:,:,3) selects the matrix of temperature values at the 3rd index of the time vector t, which corresponds to t=2.

  1. You can create contour plots for all the time points using a loop. For example:
main.m
for i = 1:length(t)
  subplot(2,3,i);
  contour(T(:,:,i));
  title(['Time = ', num2str(t(i))]);
end
100 chars
6 lines

Here, subplot is used to create a 2x3 grid of subplots, and each subplot corresponds to a time point. The title function is used to show the time value for each subplot.

Hope this helps!

gistlibby LogSnag