Derivatives in matlab

2

To do an integral in matlab we can execute the following:

syms variable

int(funcion,variable,a,b)

can a derivative be made in the same way in a symbolic way?

    
asked by Josemi 03.06.2017 в 11:05
source

1 answer

3

Yes. with diff ()

The diff () function has the following syntax

 diff(F)
 diff(F,var) 
 diff(F,n) 
 diff(F,var,n)
 diff(F,var1,...,varN)

To achieve what you propose:

Derived from a function of a variable:

syms x
f(x) = sin(x^2);
df = diff(f,x)
df(x) =
2*x*cos(x^2)

Derive functions of several variables

finds the first derivative of the expression

syms x t
diff(sin(x*t^2))
ans =
t^2*cos(t^2*x)

Since the variable to derive diff is not specified, it uses the default variable defined by symvar for that expression the variable is x:

symvar(sin(x*t^2),1)
ans =
x

Now to find the derivative of the expression with respect to the variable t:

diff(sin(x*t^2),t)
ans =
2*t*x*cos(t^2*x)

With information translated from diff () in MathWorks

    
answered by 03.06.2017 / 16:19
source