*Elementary Differential Equations and Bounday Value Problem,*by Boyce and DiPrima.

- Section 10.4, numbers 32 and 34.
- Section 10.5 numbers 18 and 22.
- Section 10.6 numbers 11 and 12. Note that bounday conditions for 12 were not covered in class, but it's a simple modification of the solution that is clearly covered in the book.
- Section 10.7 numbers 1 and 6. Note that the exact situation for number 6 was not covered in class, but is a simple enough modification that is covered in the text.
- Here is the finite difference code for the heat equation covered in class (and corrected for the u_old[] error).
Modify the code to compute an approximate numerical solution to problems 18 (a) in Section 10.5 and problem 11 in Section 10.6 (5 points each). Submit your code for each and a plot of the temperature profile at a sufficient number of times to verify your analytical answer and provide an adequate representation of the nature of the solution to the problems.
Code: Select all

`#include<stdio.h> #include<math.h> #define GRID 100 #define LENGTH 20 main() { double u[GRID+1],u_old[GRID+1]; double t,dt,t_start=0.0,t_finish=50.0; double dx,limit; int i,count=1000000; FILE *fp; dx = (double)LENGTH/(double)GRID; dt = 0.001; limit = t_finish/dt/50.0; /* only print 50 of the data points */ /* set the initial temperature profile */ for(i=0;i<GRID+1;i++) u[i] = i*dx; /* set boundary conditions */ u[0] = 10.0; u[GRID] = 0.0; fp = fopen("data.d","w"); for(t=t_start;t<t_finish;t+=dt) { /* loop through time */ printf("t = %f\n",t); for(i=0;i<GRID+1;i++) u_old[i] = u[i]; /* copy the new temp to the old */ for(i=1;i<GRID;i++) { /* loop through grid */ u[i] += dt*(u_old[i-1] - 2.0*u_old[i] + u_old[i+1])/pow(dx,2); } if(count>limit) { /* only save some of the data */ for(i=0;i<GRID+1;i++) fprintf(fp,"%f\t%f\n",i*dx,u[i]); fprintf(fp,"\n"); count = 0; } else { count++; } } }`

*Note:*I did not yet get a chance to cover this in class, but it must be the case that alpha^2*dt/dx^2 be less than or equal to 1/2 for this finite difference approch to be stable. You can fiddle with GRID and dt if you want, but the values given in the code should work. - Write a computer program that determines an approximate numerical solution for the wave equation. Use it to verify your answer for problem 1 in section 10.7. Submit your code as well as plots of the solution that verify your analytical answer as well as effectively communicate the nature of the solution.

*Hint:*while not a simple trivial change, this problem is probably best approached by modifying the code for the heat condition equation. Also, be sure to pick dt and dx so that alpha^2*dt/dx is less than or equal to 1.