Diff (f(x+h)-f(h))/h
5 次查看(过去 30 天)
显示 更早的评论
if to the question: diffresensial (f(x+h)-f(h))/h for h>0. if you can help to formula?
3 个评论
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
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 个评论
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).
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!