% Here's the diary from class. I started it by typing the command "diary Jan_15" >> cd ~ >> cd Mat1062 >> cd heat >> ls 3_30_99 for_class1.ps heat3.m heat_eul_dir.m~ neumann_heat_cn.m tri_diag.m Jan_15 for_class2.ps heat3.m~ heat_eul_neu.m periodic_tridiag.m up_solve.m class_jan_15.m goof.m heat4.m heat_eul_neu.m~ test_fft class_jan_15.m~ goof1.m heat5.m heat_eul_robin.m test_heat1 down_solve.m heat1.m heat_cn.m heat_eul_robin.m~ test_heat2 find_spec.m heat1.m~ heat_cn.m~ mode.m test_heat3 find_spec.m~ heat2.m heat_eul_dir.m my_LU.m test_heat4 >> help heat1 [u,err,x,t] = heat1(t_0,t_f,M,N) solves the heat equation u_t = D u_xx on [0,2*pi] with initial data u_0 = sin(k x) with periodic boundary conditions using finite-differences in space and explicit time-stepping. t_0 is the initial time, t_f is the final time, N is the number of intervals in space, and M is the number of intervals in time. err is the error. If I'm going to use the FFT to analyse the solution then I'd like to take N of the form 2^k. This will also have the advantage of making sure there's always a meshpoint at x = pi >> display('hit any key for more') >> pause % set the start time >> t_0 = 0; % set the end time >> t_f = 1; % set the number of subintervals of [0,2pi] >> N = 128; % set the number of subintervals of [t_0,t_f] >> M = 100; >> [u1,err,x,t1] = heat1(t_0,t_f,M,N); >> figure(1) >> for j=0:20 plot(x,u1(:,j+1),'.-') title(t1(j+1),'FontSize',16) xlabel('Explicit Euler','FontSize',16) pause(1) end >> display('hit any key for more') >> pause % Now I want to make the timestep smaller by 1/10. So I increase the number of time subintervals >> M = 1000; % Note that I'm now creating new arrays u2 and t2. I'm writing over the priorly defined err and x % (Because I'm not using err and x is the same anyway.) >> [u2,err,x,t2] = heat1(t_0,t_f,M,N); >> figure(2) >> for j=0:20 plot(x,u2(:,10*j+1),'.-') axis([0,2*pi,-1.1,1.1]) xlabel('Explicit Euler','FontSize',16) title(t2(10*j+1),'FontSize',16) pause(1) end >> display('hit any key for more') >> pause >> help heat3 [u,err,x,t] = heat3(t_0,t_f,M,N) solves the heat equation u_t = D u_xx on [0,2*pi] with initial data u_0 = sin(k x) with periodic boundary conditions using finite-differences in space and implicit time-stepping. t_0 is the initial time, t_f is the final time, N is the number of intervals in space, and M is the number of intervals in time. err is the error. If I'm going to use the FFT to analyse the solution then I'd like to take N of the form 2^k. This will also have the advantage of making sure there's always a meshpoint at x = pi >> display('hit any key for more') >> pause % I'm now going back to the original timestep that was bad for explicit Euler >> M = 100; >> [u3,err,x,t1] = heat3(t_0,t_f,M,N); >> figure(1) >> for j=0:20 plot(x,u3(:,j+1),'.-') axis([0,2*pi,-1.1,1.1]) xlabel('fully implicit','FontSize',16) title(t1(j+1),'FontSize',16) pause(1) end >> display('hit any key for more') >> pause >> help heat_cn [u,err,x,t] = heat_cn(t_0,t_f,M,N) this solves the heat equation u_t = D u_xx with initial data u_0 = sin(k x) with periodic boundary conditions using finite-differences in space and Crank-Nicolson time-stepping. t_0 is the initial time, t_f is the final time, N is the number of intervals in space, and M is the number of intervals in time. err is the error. If I'm going to use the FFT to analyse the solution then I'd like to take N of the form 2^k. This will also have the advantage of making sure there's always a meshpoint at x = pi >> display('hit any key for more') >> pause >> [u4,err,x,t1] = heat_cn(t_0,t_f,M,N); >> figure(1) >> for j=0:20 plot(x,u4(:,j+1),'.-') axis([0,2*pi,-1.1,1.1]) xlabel('Crank-Nicolson','FontSize',16) title(t1(j+1),'FontSize',16) pause(1) end % to see what objects have been defined and what their dimensions are >> whos Name Size Bytes Class Attributes M 1x1 8 double N 1x1 8 double err 128x101 103424 double j 1x1 8 double t1 1x101 808 double t2 1x1001 8008 double t_0 1x1 8 double t_f 1x1 8 double u1 128x101 103424 double u2 128x1001 1025024 double u3 128x101 103424 double u4 128x101 103424 double x 128x1 1024 double % to see a subset of that information... >> whos u* Name Size Bytes Class Attributes u1 128x101 103424 double u2 128x1001 1025024 double u3 128x101 103424 double u4 128x101 103424 double % I now close the diary. >> diary off