问题描述:

We want to study the error in the difference approximation for forward difference and central difference, tabulate the error for `h=[1.E-3 1.E-4 1.E-5 1.E-6 1.E-7 1.E-8 1.E-9 1.E-10 1.E-11 1.E-12 1.E-13]`

and draw a loglog-diagram. Any tips on how to do this?

This is our central- and forward difference.

`centdiff=(subs(f, x+h))/(2*h) - (subs(f, x-h))/(2*h)`

framdiff=(subs(f, x+h) - f)/h

And our function:

`f=60*x-(x.^2+x+0.1).^6./(x+1).^6-10*x.*exp(-x);`

The error in the approximation is the difference between the results you get using it, and the analytical result. Luckily, you have a nice function `f`

, which can easily (well, sorta) be differentiated. After finding the derivative and creating the corresponding Matlab function, you just need to compare the analytical result with the approximate result. The simplest way would probably be using a `for`

loop over your different `h`

.

So, the idea is something like this (not tested, just to give you an idea):

```
cent_error = zeros(size(h));
forw_error = zeros(size(h));
for idx = 1:size(h)
cent_error(idx) = abs(analytical_diff - centdiff(f, h));
forw_error(idx) = abs(analytical_diff - forwdiff(f, h));
end
loglog(...)
```

您可能感兴趣的文章：

- python - UnicodeDecodeError in SUDS but only in the .exe generated by py2exe
- c# - How to create image from text strings
- Evaluating equality in perl using elements taken from an array ref
- How to copy and paste SVG node using jQuery
- c++ - Tell VS2010 to collapse regions
- php - Reading a specific line from a text file
- clr - Any implementation of an Unrolled Linked List in C#?
- Finding Hudson Log Files
- Forward to a payment-gateway together with POST data using cURL (or any other PHP server side solution)
- WCF in Winforms app - is it always single-threaded?

随机阅读：

**推荐内容**-

**热点内容**-
- php - Reading a specific line from a text file
- clr - Any implementation of an Unrolled Linked List in C#?
- Finding Hudson Log Files
- Forward to a payment-gateway together with POST data using cURL (or any other PHP server side solution)
- WCF in Winforms app - is it always single-threaded?
- git svn - git svn fetch does not fetch a Subversion commit message modified after initial clone
- java me - Why I am getting the bad length exception when I am running this application?
- java - How to get string.format to complain at compile time
- ruby on rails - Trigger observer of parent class on change
- python - Issue with URL pattern in Django with webmonkey tutorial