# Numerical Differentiation Homework Online

## Math 128A: Numerical Analysis (Summer 2015)

Description: | Basic concepts and methods in numerical analysis: Solution of equations in one variable; Polynomial interpolation and approximation; Numerical differentiation and integration; Initial-value problems for ordinary differential equations; Direct methods for solving linear systems. Prerequisites: Math 53 and 54, basic programming skills. |
---|---|

Piazza: | Piazza Link (All announcements and resources are posted here) |

Lecturer: | Qiuyi (Richard) Zhang, qiuyi@math.berkeley.edu |

Lectures: | MTuWTh 12-1:00pm, 289 Cory |

Discussions: | TuTh 1-2:00pm, 289 Cory (Bring your own laptop with MATLAB installed!) |

Office Hours: | Tuesday 2-3:30pm and Monday 1-2:30pm, 848 Evans |

Textbook: | R. L. Burden and J. D. Faires, Numerical Analysis, 9th edition, Brooks-Cole, 2010. ISBN-13: 978-0-538-73351-9; ISBN-10: 0-538-73351-9 |

MATLAB: | The commercial software MATLAB will be used in the class, and there are various alternatives for using it: MATLAB BooksJ. Dorfman, Introduction to MATLAB Programming, Decagon Press, Inc. Available at Krisha Copy Center on University Avenue, on demand for about $20 + tax. Please email them your order at orders@krishnacopy.com, with name and phone number, and it will be available for pick up later.Otto and Denier, An Introduction to Programming and Numerical Methods in MATLAB (online version) Quarteroni and Saleri, Scientific Computing with MATLAB and Octave (online version) K. Sayood, Learning programming using MATLAB (online version) Instructions for setting up a UC Berkeley Library Proxy Server for off-campus access to online books |

Grading and policies: | Homework: Weekly homework is posted on this course page, and it is in general due in each Tuesday discussion section. Group discussions about the homework are encouraged, but each student must write his/her own solutions and not copy them from anyone else. Late homework will not be accepted, but the lowest score will be dropped when computing the grade.Programming Assignments: There will be a total of 2 programming assignments, based on the MATLAB programming language. Group discussions about the assignments are encouraged, but each student must write his/her own computer codes and report, and not copy them from anyone else. Late submissions will not be accepted, and both assignments will count towards the grade.Exams: There will be two in-class midterm exams and one final exam. The first midterm exam will be given on the third week and the second will be on the sixth week. The final is on the last day of class and your final exam grade may replace one of your midterm grades. Grade corrections: The grades for exams will be changed if problems are brought to the attention immediately after the exams are returned.Grades: The final grade will be based on weekly homework assignments (20%), the programming assignments (10%), the midterm exams (20% each), and the final exam (30%). If it improves your grade, we will count one of the midterm exam (0%) and the final exam (50%). This allows you to miss one of the two midterm exams, but your chances are improved if you take both. Special arrangements: If you are a student with a disability registered by the Disabled Student Services (DSS) on UCB campus and if you require special arrangements during exams, you must provide the DSS document and make arrangements via email or office hours prior to each exam, explaining your circumstances and what special arrangements need to be done. |
---|

MATLAB Codes: | 1: bisection.m, bisection_table.m2: fixedpoint.m, fixedpoint_table.m, fixedpoint_plot.m, fixedpoint_demo.m, newton.m, newton_table.m, newton_plot.m3: steffensen.m, steffensen_table.m, horner.m, muller.m, muller_table.m, muller_plot.m4: neville.m, ncspline.m, ccspline.m, splineeval.m, diffsplineeval.m, spline_demo.m5: diff_demo.m, rich_demo.m, romberg.m, adaptive_demo.m, gaussquad.m6: rk4.m, rkf.m | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|

Relevant Resources: | 1: Programming Assignment 12: Sample Midterm 1, Solutions3: Midterm 1, Solutions4: Sample Midterm 2, Solutions5: Programming Assignment 26: Midterm 2, Solutions | ||||||||||||||||||||||||

Homework Assignments: |
| ||||||||||||||||||||||||

Syllabus (Tentative): |
| ||||||||||||||||||||||||

9 | 3.2: Data Approximation and Neville's Method 3.4: Hermite Interpolation | ||||||||||||||||||||||||

10 | 3.5: Cubic Spline Interpolation | ||||||||||||||||||||||||

11 | (Practice Exam on Website/Piazza) Midterm Exam - In class | ||||||||||||||||||||||||

12 | 4.1: Numerical Differentiation | ||||||||||||||||||||||||

13 | 4.2: Richardson's Extrapolation 4.3: Elements of Numerical Integration | ||||||||||||||||||||||||

14 | 4.3: Elements of Numerical Integration 4.4: Composite Numerical Integration | ||||||||||||||||||||||||

15 | 4.5: Romberg Integration 4.6: Adaptive Quadrature Methods | ||||||||||||||||||||||||

16 | 4.7: Gaussian Quadrature 4.8: Multiple Integrals | ||||||||||||||||||||||||

17 | 5.1: The Elementary Theory of Initial-Value Problems | ||||||||||||||||||||||||

18 | 5.2: Euler's Method | ||||||||||||||||||||||||

19 | 5.2: Euler's Method 5.3: Higher-Order Taylor Methods | ||||||||||||||||||||||||

20 | 5.4: Runge-Kutta Methods 5.5: Error Control and the Runge-Kutta-Fehlberg Method | ||||||||||||||||||||||||

21 | 5.6: Multistep Methods 5.7: Variable Step-Size Multistep Methods | ||||||||||||||||||||||||

22 | 5.9: Higher-Order Equations and Systems of Differential Equations 5.10: Stability | ||||||||||||||||||||||||

23 | (Practice Exam on Website/Piazza) Midterm Exam - In class | ||||||||||||||||||||||||

24 | 5.10: Stability 5.11: Stiff Differential Equations | ||||||||||||||||||||||||

25 | 6.1: Linear Systems of Equations 6.3: Linear Algebra and Matrix Inversion | ||||||||||||||||||||||||

26 | 6.4: The Determinant of a Matrix 6.6: Special Types of Matrices | ||||||||||||||||||||||||

27 | 6.6: Special Types of Matrices 7.1: Norms of Vectors and Matrices | ||||||||||||||||||||||||

28 | 7.2: Eigenvalues and Eigenvectors | ||||||||||||||||||||||||

29 | 7.3: Jacobi and Gauss-Siedel Iterative Techniques Review | ||||||||||||||||||||||||

30 | Review | ||||||||||||||||||||||||

31 | NO CLASS | ||||||||||||||||||||||||

32 | Final Exam - In class |

MATLAB has a **diff** command that takes a list of numbers and calculates the difference between each adjacent number.

Example: **y = [1,3,8]; dy = diff(y)** → [2,5].

(Note that the result has one less value than the original list.)

Numerical derivative - if you have lists of x and y values, **diff(y)./diff(x)** will give the slope of each interval.

Example:** x = [0,1,3]; y=[1,5,4]; dydx=diff(y)./diff(x)** → [4,-1] ./ [1,2] → [4,-0.5]

When using yp=diff(y)./diff(x) you need to map it to an associated x value. Since you are, in essence, calculating the slope of a line segment, you can map the slope to one of three x values:

**forward difference**- map the slope to the beginning point

use xp=x(1:end-1)**backward difference**- map the slope to the end point

use xp=x(2:end)**central difference**- map the slope to the midpoint

use xp=x(1:end-1) + diff(x)./2

Note: numerical differentiation will magnify noise and experimental error in your data. It is usually necessary to filter the data or curve fit it to obtain better results.

Run diff_ex1.m for a simple example.

File(s):

diff_ex1.m

Practice: Create a program to numerically differentiate this data set. Plot the original data set and its derivative (central difference) on the same plot.

t=0:0.1:5;

y=[ 40.0 41.2 42.2 43.2 44.0 44.8 45.4 46.0 46.5 46.8 47.1 47.3 47.3 47.3 47.2 47.0 46.7 46.2 45.7 45.1 44.4 43.6 42.7 41.7 40.6 39.4 38.1 36.7 35.2 33.6 31.9 30.1 28.2 26.2 24.2 22.0 19.7 17.3 14.8 12.3 9.6 6.8 4.0 1.0 -2.1 -5.2 -8.5 -11.8 -15.3 -18.8 -22.5 ];

File(s):

diff_ex2_sameplot.m, diff_ex2_subplot.m