Professional Documents
Culture Documents
Agenda
1. Symbolic maths
2. Differentiaion
3. Partial differentiaion
4. Plotting differentiation
5. Jacobian
6. Plotting symbolic using implicit function
Symbolic Maths lets user to analytically perform differentiation, integration, simplification, transforms, and
equation solving. User can perform dimensional computations and convert between units. Computations can be
performed either analytically or using variable-precision arithmetic, with the results displayed in mathematical
typeset.
Syms creates symbolic scalar variables & functions, and matrix variables & functions
In MATLAB, syms is used as a shortcut to the inbuilt function sym. This function can be used to create symbolic
variables. The Symbolic variables used in MATLAB are not constants like the regular variables; we do not
assign values to them. These are used to solve various expressions with the help of functions available in
Symbolic Math Toolbox. The syms function creates a symbolic object that is automatically assigned to a
MATLAB variable with the same name. (https://www.educba.com/matlab-syms/)
We can allot values for the symbolic variables as and when needed. Let
1
a % display a
a =
x % display x
x =
We see that system displays nothing for a and x as a matrix with values x1_1 and so on (but no value is
attached to them). Values to symbolic variables can be assigned later on
a =
ans =
That is just a brief introduction to symbolic mathematics. Using this information, we need to compute
differentiation, partial differentiation and Jacobian operators. They are considered in next parts
3.2 Differentiation
For differentiation, we will use syms and define a function. Then we shall (symbolically) differentiate the
function
clear; clear all % clear the variables declared earlier (if any)
syms x ; % define a symbol x
f= 5*x^3 + 4*x^2 + 3*x % Define a function
f =
2
What happens if the last variable is 3*x*y?
clear; clear all % clear the variables declared earlier (if any)
syms x y; % define a symbol x
f= 5*x^3 + 4*x^2 + 3*x*y % Define a function
f =
In partial differentiation, we have two variables. We differentiate with each variable, treating the one variable(s)
as constant
f =
fs =
fy =
clear; clc
syms x y;
u = exp (x) * (x * cos(y) - y * sin(y))
u =
3
duxy =
duyx =
proved
clear; clc
syms x y ; % define symbolic variables
u = exp (x)*(x*cos(y) - y*sin(y)); %define function
dux = diff (u , x ); % first (partial) derivative
duy = diff (u , y );
uxx = diff ( dux , x ); % second (partial) derivative of u w . r . t x
uyy = diff ( duy , y );
w=uxx+uyy % sum of both partial functions
w =
w1 =
ans =
Generate a sine wave and differentiate it. Plot both the curves
f =
fs =
4
a=matlabFunction(f) % convert the symbolic value to plottable value
b= matlabFunction(fs)
Let us differentiate twice (2nd order differentiation) and plot original, first-order and second-order differentiaions
syms t;
x = t*exp(-3*t)+0.25*exp(-3*t) % define a function
x =
xdot =
5
xddot = diff(x,t,2) % second order differentiation
xddot =
subplot(311);
fplot(x1,[0 3]) % plot the original signal
subplot(312);
xdot1=matlabFunction(xdot)
6
3.5 Jacobian
If x = g(u, v) and y = h(u, v) are transformation of the plane. Then the Jacobian of this transformation is
J =
7
det(J) % find the determinant (verify it is 4)
ans =
If u = x + 3y2 − z3, v = 4x2yz, w = 2z2 − xy then prove that at (1, −1, 0), J = 20
J =
J1 =
ans =
figure()
f1 = @(x,y) x.^2 + y.^2 - 1; %define function for a circcle
fimplicit(f1,'r') % plot it with red color
8
% you may want to try with axis equal
syms x y ;
f2 = @(x,y) y.^2 * (2-x)- x.^2 * (2+x) ;
figure()
fimplicit(f2, [-4 4 -5 5]);
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize
your function to return an output with the same size and shape as the input arguments.
9
narasimha.kaulgud@nie.ac.in
10