How to find the derivative without using a symbolic function in Matlab?

Numerical Analysis: How does one write a MATLAB program to find the derivative of f(x)=xcosxf(x)=x^{\cos x}  using the Richardson extrapolation table?

  • Can anyone write a MATLAB program to find the derivative of the following: f(x)=xcos(x) f(x)=x^{cos(x)} The inputs to the program are: x h The outputs are f'(x) = D(3,3), The estimated error = D(3,3) - D(3,2) Theoretically, I can solve it using the Richardson extrapolation table: Where: and:

  • Answer:

    Instead of Richardson's, you can use the complex step derivative, which gives pretty accurate first order derivatives (depending on the chosen hh) The formula is: f'(x) \approx \frac{Im(f(x +ih))}{h} The code can be as simple as this: >>> f = @(x) x^(cos(x)); >>> h = eps; >>> x0 = 1.1; >>> df = imag(f(x0 + sqrt(-1)*h))/h See here for some background on complex step derivatives. http://en.wikipedia.org/wiki/Numerical_differentiation#Complex_variable_methods I should add that your particular function does not have real-valued derivatives everywhere.

Paul Artois at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.