Fortune Telling Collection - Fortune-telling birth date - How to find the differential of function with MATLAB

How to find the differential of function with MATLAB

Use the diff command

Symbolic operation

The Diff function is used to calculate the differential term of the function, and the related function syntax is as follows:

Diff(f) returns the first differential value of f to the preset independent variable.

Diff(f,' t') returns the first differential value of f to the independent variable t.

Diff(f, n) returns the nth differential value of f to a preset independent variable.

Diff(f,' t', n) returns the nth differential value of f to the independent variable t.

That is, the calling format of matlab derivative command diff:

The first derivative of Diff (function);

The nth derivative of Diff (function, n) (n is a specific integer);

Diff (function, variable name), find the partial derivative of the pair;

Diff (function, variable name, n), find the n-order partial derivative of the pair;

Diff is also used in numerical differential function, so this function depends on input parameters to decide whether it is numerical differential or sign differential. If the parameter is a vector, numerical differentiation is performed, and if the parameter is a symbolic expression, symbolic differentiation is performed. If a one-dimensional vector of length n is input, the function will return a vector of length n- 1, and the value of the vector is the difference between the adjacent elements of the original vector, so the finite difference approximation of the first derivative can be calculated.

First, define the following three equations, and then calculate their differential terms:

& gt& gts 1 = '6*x^3-4*x^2+b*x-5';

& gt& gtS2 =' Crime (1)';

& gt& gtS3 = '( 1-t^3)/( 1+t^4)';

& gt& gt difference (S 1)

ans= 18*x^2-8*x+b

& gt& gt difference (S 1, 2)

ans= 36*x-8

& gt& gtdiff(S 1,' b ')

ans= x

& gt& gt difference (S2)

ans= cos(a)

& gt& gt difference (S3)

ans=-3*t^2/( 1+t^4)-4*( 1-t^3)/( 1+t^4)^2*t^3

& gt& gt Simplification (Difference (S3))

Answer = t 2 * (-3+t 4-4 * t)/(1+t 4) 2