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

5 vues (au cours des 30 derniers jours)
lola lola
lola lola le 8 Avr 2017
Commenté : Star Strider le 8 Avr 2017
if to the question: diffresensial (f(x+h)-f(h))/h for h>0. if you can help to formula?
  3 commentaires
lola lola
lola lola le 8 Avr 2017
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 le 8 Avr 2017
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.

Connectez-vous pour commenter.

Réponses (1)

Star Strider
Star Strider le 8 Avr 2017
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 commentaires
lola lola
lola lola le 8 Avr 2017
Can you help to write the script?
Star Strider
Star Strider le 8 Avr 2017
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).

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by