Differentiation in Script Matlab

  • Context: MATLAB 
  • Thread starter Thread starter c299792458
  • Start date Start date
  • Tags Tags
    Differentiation Matlab
Click For Summary

Discussion Overview

The discussion revolves around performing differentiation on user-defined functions in MATLAB scripts. Participants explore methods for implementing differentiation, including symbolic differentiation and numerical approximation, while considering the application of both the function and its derivative throughout the script.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant inquires about creating a script that differentiates a user-defined function and applies both the function and its derivative throughout the script.
  • Another participant suggests that without using symbolic features, the user must either provide both the function and its derivative or use numerical approximation for the derivative.
  • A later reply mentions the possibility of writing a basic differentiation function in MATLAB but notes the need for tokenizing the input to apply differentiation patterns.
  • Some participants propose that for extensive symbolic math, using dedicated symbolic math software or toolboxes may be more effective than MATLAB's built-in capabilities.

Areas of Agreement / Disagreement

Participants express differing views on the best approach to differentiation in MATLAB, with some advocating for symbolic methods and others suggesting numerical approximation or manual entry of derivatives. No consensus is reached on a single method.

Contextual Notes

Participants highlight limitations in MATLAB's handling of derivatives, including the need for symbolic features or the challenges of numerical approximation. There are also considerations regarding variable naming conventions in MATLAB.

Who May Find This Useful

This discussion may be useful for MATLAB users interested in implementing differentiation in their scripts, particularly those exploring symbolic versus numerical methods for calculus operations.

c299792458
Messages
67
Reaction score
0
How might I make my script perform differentiation on a user-defined function? I also want the function and its derivative (in the form of a function) to be applied throughout the script, say in the forms of f and f' respectively, which I believe requires str2func.

Example: The user is prompted for an f(x). He enters x^3. Then both x^3 and 3*x^2 are applied in the place of f and f' throughout the script.

Thanks in advance!
 
Physics news on Phys.org
c299792458 said:
How might I make my script perform differentiation on a user-defined function? I also want the function and its derivative (in the form of a function) to be applied throughout the script, say in the forms of f and f' respectively, which I believe requires str2func.

Example: The user is prompted for an f(x). He enters x^3. Then both x^3 and 3*x^2 are applied in the place of f and f' throughout the script.

Thanks in advance!

See my answer to your related question in the Math Software sub-forum.

Unless you are using the "symbolic" features, the only options you have for the derivative is to either make the user enter both the function and the derivative or else you can approximate the derivative numerically as (f(x+h) - f(x))/h for some suitably small h.

BTW f' is not a suitable name for a variable in matlab. You'll have to choose something else to denote the derivative (df or fd for example).
 
thanks! :)
 
You could write yourself a really, really basic differentiation function / script in MATLAB, but you'd have to do tokenizing to break down the entry and then apply the appropriate differentiation pattern.

But if you're looking to do a lot of symbolic math, you're better off with an actual symbolic math package (e.g. Mathematica, Maple, or the Symbolic Math Toolbox for MATLAB). There's also a few open-source / freeware ones available (like Maxima or Axiom, both with various add-on GUIs):
http://en.wikipedia.org/wiki/Comparison_of_computer_algebra_systems
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
1
Views
2K
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 19 ·
Replies
19
Views
2K