UNIT-2_MATLAB Programs
UNIT-2_MATLAB Programs
(i) syms x
%define a function
f=cos(5*x)*cos(3*x)
diffn=simplify(diff(f,x,5))
out put
diffn =
- 16*sin(2*x) - 16384*sin(8*x)
(ii)
syms x
%define a function
g=exp(x)*sin(sqrt(3)*x)
diffn=simplify(diff(g,x,5))
output:
diffn =
-32*exp(x)*cos(pi/6 + 3^(1/2)*x)
(iii) syms x
%define a function
h=exp(2*x)*cos(x)*cos(2*x)
diffn=simplify(diff(h,x,5))
output:
diffn =
Code:
syms x
%define a function
f1=log(x)/x
diffn=simplify(diff(f1,x,1))
diffn=simplify(diff(f1,x,2))
diffn=simplify(diff(f1,x,5))
Output:
diffn =
-(log(x) - 1)/x^2
diffn =
(2*log(x) - 3)/x^3
diffn =
-(2*(60*log(x) - 137))/x^6
3. If y cos log x2 2 x 1 show that
x 12 yn2 2n 1 x 1 yn1 n2 4 yn 0 .
syms x
%define a function
f=cos(log(x^2-2*x+1));
n=5;
%(n+2)th derivative of the function
A = simplify(diff(f,x,n+2));
%(n+1)th derivative of the fucntion
B = simplify(diff(f,x,n+1));
% nth derivative of the fucntion
C = simplify(diff(f,x,n));
result = simplify((x-1)^2*A+(2*n+1)*(x-1)*B+(n^2+4)*C)
if (result == 0)
disp("Given is proved")
else
disp("It is not correct")
end
T = taylor(f,var) T =
taylor(f,var) approximates f wit
h the Taylor series
expansion of f up to the fifth
order at the point var = 0. If
you do not specify var,
then taylor uses the default
variable determined
by symvar(f,1).
T = taylor(f,var,a) T =
taylor(f,var,a) approximates f w
ith the Taylor series expansion
of f at the point var = a.
T = T =
taylor(___,Name,Valu taylor(___,Name,Value) specifies
e) options using one or more name-
value arguments in addition to
any of the input argument
combinations in previous
syntaxes. For example, you can
specify the expansion point,
truncation order, or order mode
of the Taylor series expansion.
syms x
%define the funciton
f=log(cos(x))
%Taylors series is upto first five non-zero terms
T1= taylor(f,x,pi/3)
%using ExapansioPoing
T2 = taylor(f,x,"ExpansionPoint", pi/3)
%Using trunction order
T3 = taylor(f,x,"ExpansionPoint", pi/3,"Order",7)
x 2 x 4 x6
5. Show that log e sec x ......... by using Maclaurin’s
2 12 45
series. Write an appropriate MATLAB code and the plot
the same.
Code:
syms x
%define the funciton
T = taylor(log(sec(x)),x,"Order",10)
Output:
T =
syms x
%define the function
T = taylor(log(1+cos(x)))
Output:
T =
Code:
syms x
%define a function
f = 1/x-log(1+x)/x^2
% limit of a function at x tends to 0
Lim_val=limit(f,x,0)
Output:
Lim_val=
1/2
(ii)
syms x
%define a function
g = ((1^(1/x)+2^(1/x)+3^(1/x))/3)^(3*x)
% limit of a function at x tends to 0
Lim_val1=limit(g,x,inf)
Output:
im_val1 =
6
Evaluate the following:
1
(i) lim x (ii) lim
1 1 sinx x2
. Write an appropriate
x0 x e 1 x0 x
MATLAB code.
Code:
syms x
%define a function
kkkf = 1/(x-2)-log(x-1)
Output:
Lim_val =
-1/2
(ii)
syms x a b c
%define a function
g = ((a^x+b^x+c^x)/3)^(1/x);
% limit of a function at x tends to 0
Lim_val1=limit(g,x,0)
Output:
Lim_val1 =
a^(1/3)*b^(1/3)*c^(1/3)
9. Evaluate the following:
1 sin x cos x log(1 x)
lim . Write an appropriate MATLAB code.
x 0 x tan 2 x
Code:
%define a function
f2 = ((1+sin(x)-cos(x)+log(1-x))/(x*(tan(x))^2));
% limit of a function at x tends to 0
Lim_val2=limit(f2,x,0)
Output:
Lim_val2 =
-1/2
MATLAB code.
syms x
%define a function
f3=1/x-1/(exp(x)-1)
Lim_val3=limit(f3,x,0)
Output:
Lim_val3 =
1/2
(ii)
syms x
%define a function
f4 = (sin(x)/x)^(1/x^2)
% limit of a function at x tends to 0
Lim_val4=limit(f3,x,0)
Output:
Lim_val4 =
1/2