the second workshop()

notice:The detailed code is not presented in this article

1. For the polynomial f(x) = x^4 – 2*x^3 , calculate the derivative and the 2nd derivative analytically (the first derivative so that you can compare with your numerical derivatives to determine the error, and the second derivative might be useful for understanding your results—see equations (1.4) and (1.6)).

a) Choose different step sizes h and plot a log-log graph of error vs step size to compare the numerical derivatives found using the forward, backward, and central difference formulas with the actual derivative. How accurate are the numerical derivatives at x = 0, 1, 1.5, and 2? At what step sizes do you obtain the minimum errors, and what are the minimum errors (see Sauer figure 5.1)? Do you expect that this would be a problem? What if you were using single-precision floating point? (You can easily try this in Matlab by using the single() function.)

b) Add some additional error to your polynomial. For example, try y = f(x) + 0.001 * randn(size(x));. How does the error in the numerical derivative vary with step size h? Try changing the size of the error.

Checklist Did you differentiate the function (including with added error)? Did you explain how you did it? Did you plot graphs showing the error vs step size at each point? Are your graphs and axes properly labelled? Did you discuss whether the results were what you expected? Did you discuss any unusual results? Did you include code where appropriate? Did you reference the source of any code you didn’t write?

(1).result

1.the three function’s code(omitted)

2.find minimize h and different errors(omitted)

3..the log-log graph of error vs step size

the picture:

when x=0

the second workshop()_第1张图片

When x=1

the second workshop()_第2张图片

When x=1.5

the second workshop()_第3张图片

when x=2

the second workshop()_第4张图片

The total graph: 

the second workshop()_第5张图片

5. using single-precision floating point

 picture:

when x=0

the second workshop()_第6张图片

 when x=1

the second workshop()_第7张图片 when x=1.5

the second workshop()_第8张图片

when x=2

the second workshop()_第9张图片

 The total graph:

the second workshop()_第10张图片

6.full project’s codes

(2).result

When x=0

the second workshop()_第11张图片

when x=1

the second workshop()_第12张图片

 When x=1.5

the second workshop()_第13张图片when x=2

the second workshop()_第14张图片

The total graph:

the second workshop()_第15张图片

你可能感兴趣的:(学习)