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

When x=1

When x=1.5

when x=2

The total graph: 

5. using single-precision floating point

 picture:

when x=0

 when x=1

 when x=1.5

when x=2

 The total graph:

6.full project’s codes

(2).result

When x=0

when x=1

 When x=1.5

when x=2

The total graph:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值