Symbolic Differentiation in Matlab

Click For Summary
SUMMARY

This discussion focuses on symbolic differentiation in Matlab, specifically using inline functions. The user initially encounters an issue where the derivative of an inline function does not return the desired vectorial notation. By utilizing the 'vectorize' function, the user successfully transforms the output to the correct format. The final code snippet demonstrates how to achieve the desired result using 'vectorize' on the differentiated inline function.

PREREQUISITES
  • Understanding of Matlab inline functions
  • Familiarity with symbolic differentiation in Matlab
  • Knowledge of vectorized operations in Matlab
  • Basic experience with Matlab syntax and functions
NEXT STEPS
  • Explore Matlab's 'vectorize' function for handling vector operations
  • Learn about symbolic math toolbox functions in Matlab
  • Investigate advanced symbolic differentiation techniques in Matlab
  • Review best practices for optimizing inline functions in Matlab
USEFUL FOR

Matlab users, particularly those involved in mathematical modeling, engineering simulations, or anyone needing to perform symbolic differentiation efficiently.

calt3ch
Messages
4
Reaction score
0
Hi, quick question.

I have an inline function I would like to differentiate symbolically in Matlab, however when I do it I get the following:

say

x = inline('cos(t.^2)','t') ;
xp = inline(char(diff(x(t),sym('t'))),'t') ;

xp(t) becomes

-sin(t^2)*t

however I really want:

-sin(t.^2).*t (vectorial notation)

I've looked at the diff function help, and it's a bit bare (as I would expect any symbolic manipulation functions to be in Matlab lol) and doesn't seem to say how I get this derivative to handle vectors the way I want it to...

Thank you.
 
Physics news on Phys.org
Haha I just found the function 'vectorize' (which I had never used before).

Pretty much you take any inline function and it will vectorize it for you.

Thus:

x = inline('cos(t.^2)','t') ;
xp = inline(char(diff(x(t),sym('t'))),'t') ;

vectorize(xp)

gives

-sin(t.^2).*t

Thanks and sorry to bother you guys :)
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K