Symbolic Differentiation in Matlab

In summary, the conversation is about differentiating an inline function symbolically in Matlab and finding a way to handle vectors in the derivative correctly. The solution was to use the function 'vectorize' which converts the inline function to handle vectors.
  • #1
calt3ch
4
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
  • #2
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 :)
 

What is symbolic differentiation in Matlab?

Symbolic differentiation in Matlab is the process of calculating the derivative of a mathematical expression using symbolic variables and operations. It allows for the exact derivative to be calculated without the need for numerical approximations.

Why is symbolic differentiation useful?

Symbolic differentiation is useful because it provides an exact solution to the derivative of a mathematical expression. This can be especially helpful in situations where numerical approximations may not be accurate enough or when dealing with complex mathematical expressions.

How do I perform symbolic differentiation in Matlab?

To perform symbolic differentiation in Matlab, you can use the "diff" function. This function takes in the expression to be differentiated and the variable with respect to which the differentiation is to be performed.

Can symbolic differentiation handle multivariate expressions?

Yes, symbolic differentiation in Matlab can handle multivariate expressions. The "diff" function allows for differentiation with respect to multiple variables, and the resulting expression will contain all the derivatives with respect to those variables.

Is it possible to simplify the resulting expression after symbolic differentiation?

Yes, it is possible to simplify the resulting expression after symbolic differentiation in Matlab. You can use the "simplify" function to simplify the expression, making it easier to read and work with.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
951
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
904
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Back
Top