Diff (f(x+h)-f(h))/h

5 次查看(过去 30 天)
lola lola
lola lola 2017-4-8
if to the question: diffresensial (f(x+h)-f(h))/h for h>0. if you can help to formula?
  3 个评论
lola lola
lola lola 2017-4-8
yes geoff, The derivative of a function f can be approximated by f(x+h)-f(x)/h. for h>0. Write an m-file to define the function derive that takes as input a function f and two :h and x. On return is the approximation for the derivative f'(x), computed using the formula above.
can you help answer this question?
John D'Errico
John D'Errico 2017-4-8
But this is your homework. We can help you to fix a problem, but you need to try it, as otherwise, you don't learn. So make an effort, instead of just giving up. Show where you are having a problem. Then you are more likely to get help here.

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2017-4-8
The code is exactly as you wrote it for the actual calculation. To construct the function, see the documentation on Function Basics. You will have to test for ‘h>0’ (although the practical lower limit is 1E-8).
  2 个评论
lola lola
lola lola 2017-4-8
Can you help to write the script?
Star Strider
Star Strider 2017-4-8
I cannot without completely giving you the solution. It is a very straightforward problem.
First, experiment with your equation alone and see how it works with various functions. So for example, if you are using your equation to take the numerical derivative of sin, your equation should return close to the same output as the cos of the same angle. (It will not be exactly the same, so close enough is good enough.)
When you are certain your equation is working, then read about functions in the link I gave you, and put it in a function file. Remember to test for h>0 in your function, write an error message if it is not. Read the documentation for the error function to help you with that.
Also, the first few lines of your function should describe your function, what it does, and how to use it, using comment lines (starting with % in each line).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by