MATLAB Symbolic Differentiation in Matlab

AI Thread Summary
The discussion centers on differentiating an inline function symbolically in MATLAB. The user initially encounters an issue where the derivative of the function results in a standard format instead of the desired vectorized notation. Specifically, the derivative of the function `cos(t.^2)` is computed, but it returns `-sin(t^2)*t` instead of the preferred `-sin(t.^2).*t`. After reviewing the MATLAB documentation, the user discovers the `vectorize` function, which successfully converts the inline function into the desired vectorized format. This solution effectively resolves the user's problem, demonstrating the utility of the `vectorize` function in handling symbolic differentiation for vector operations in MATLAB.
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
Views
1K
Replies
1
Views
2K
Replies
5
Views
3K
Replies
4
Views
1K
Replies
5
Views
2K
Replies
4
Views
3K
Back
Top