1 / 3

Lecture 24: Numerical differentiation

Lecture 24: Numerical differentiation. diffexamp.m. %Example of numerical differentiation f=inline('exp(-x)'); fder=inline('-exp(-x)'); x0=0; hvec=zeros(15); i=1:16; hvec=10.^(-i); for ii=1:16 fdernum=(f(x0+hvec(ii))-f(x0))/(hvec(ii));

ismail
Download Presentation

Lecture 24: Numerical differentiation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 24: Numerical differentiation diffexamp.m %Example of numerical differentiation f=inline('exp(-x)'); fder=inline('-exp(-x)'); x0=0; hvec=zeros(15); i=1:16; hvec=10.^(-i); for ii=1:16 fdernum=(f(x0+hvec(ii))-f(x0))/(hvec(ii)); disp(['h=',num2str(hvec(ii)),' Error in forward-difference formula =', num2str(fdernum-fder(x0))]);%display value of function f(x) end for ii=1:16 fdernum=(f(x0+hvec(ii))-f(x0-hvec(ii)))/(2*hvec(ii)); disp(['h=',num2str(hvec(ii)),' Error in three-point centered-difference formula =', num2str(fdernum-fder(x0))]);%display value of function f(x) end

  2. >> diffexamp h=0.1 Error in forward-difference formula =0.048374 h=0.01 Error in forward-difference formula =0.0049834 h=0.001 Error in forward-difference formula =0.00049983 h=0.0001 Error in forward-difference formula =4.9998e-005 h=1e-005 Error in forward-difference formula =5e-006 h=1e-006 Error in forward-difference formula =5.0002e-007 h=1e-007 Error in forward-difference formula =5.0486e-008 h=1e-008 Error in forward-difference formula =6.0775e-009 h=1e-009 Error in forward-difference formula =2.8282e-008 h=1e-010 Error in forward-difference formula =-8.274e-008 h=1e-011 Error in forward-difference formula =-8.274e-008 h=1e-012 Error in forward-difference formula =2.2122e-005 h=1e-013 Error in forward-difference formula =-0.00031095 h=1e-014 Error in forward-difference formula =0.00079928 h=1e-015 Error in forward-difference formula =0.00079928 h=1e-016 Error in forward-difference formula =-0.11022

  3. h=0.1 Error in three-point centered-difference formula =-0.0016675 h=0.01 Error in three-point centered-difference formula =-1.6667e-005 h=0.001 Error in three-point centered-difference formula =-1.6667e-007 h=0.0001 Error in three-point centered-difference formula =-1.6669e-009 h=1e-005 Error in three-point centered-difference formula =-1.2102e-011 h=1e-006 Error in three-point centered-difference formula =2.6755e-011 h=1e-007 Error in three-point centered-difference formula =5.2636e-010 h=1e-008 Error in three-point centered-difference formula =6.0775e-009 h=1e-009 Error in three-point centered-difference formula =-2.7229e-008 h=1e-010 Error in three-point centered-difference formula =-8.274e-008 h=1e-011 Error in three-point centered-difference formula =-8.274e-008 h=1e-012 Error in three-point centered-difference formula =-3.3389e-005 h=1e-013 Error in three-point centered-difference formula =0.00024417 h=1e-014 Error in three-point centered-difference formula =0.00079928 h=1e-015 Error in three-point centered-difference formula =-0.054712 h=1e-016 Error in three-point centered-difference formula =0.44489

More Related