Professional Documents
Culture Documents
Shiva Matlab
Shiva Matlab
10
11
Jana Bhawana Campus, Godawari-11
Practical file record, BCA Second semester
Mathematics-II- CAMT 154
Name of student:
Introduction to matlab
Calculus is an essential subject in mathematics required for science and engineering students. It contains two
main topics which are the differentiation and integration of functions. The former one is based on
understanding the determination of limits. Often, many students do not enjoy studying these topics because
they have to memorize formulas for deriving solutions. Some solutions require a long time to derive by
employing specific techniques. Furthermore, most students do not appreciate learning these topics because they
don’t know when the solutions will be used for realistic problems.
With the capability of the symbolic manipulation software today, solutions to calculus problems can be
obtained rapidly.
Introduction to calculus
Calculus is an essential subject in mathematics required for science and engineering students. It contains
two main topics which are the differentiation and integration of functions. The former one is based on
understanding the determination of limits. Often, many students do not enjoy studying these topics because
they have to memorize formulas for deriving solutions. Some solutions require a long time to derive by
employing specific techniques. Furthermore, most students do not appreciate learning these topics because
they don’t know when the solutions will be used for realistic problems.
With the capability of the symbolic manipulation software today, solutions to calculus problems can be
obtained rapidly.
Limits:
Introduction to matlab
Calculus is an essential subject in mathematics required for science and engineering students. It contains two
main topics which are the differentiation and integration of functions. The former one is based on
understanding the determination of limits. Often, many students do not enjoy studying these topics because
they have to memorize formulas for deriving solutions. Some solutions require a long time to derive by
employing specific techniques. Furthermore, most students do not appreciate learning these topics because they
don’t know when the solutions will be used for realistic problems.
With the capability of the symbolic manipulation software today, solutions to calculus problems can be
obtained rapidly.
Demonstrate limit using matlab
2
1.lim x −4
x →2
syms x y
>> limit(x^2 - 4),x, 2,
ans =
-4
x=
ans =
>>
3
x −4 x
2.lim 2
x →2 2 x +3 x
>> syms x y
>> limit(x^3 - 4*x/2*x^2+3*x),x, 0,
ans =
x=
ans =
3
x
3. lim 2
x→−1 (x+ 1)
limit(x^3 /(x+1)^2),x,-1,
ans =
0
x=
ans =
-1
4.
( x +1 )2 ( x−1)
lim 3
x→−1 x +1
ans =
NaN
x=
ans =
-1
lim ¿
3 2
x −x
−¿
x→ 0 3 2
¿
x +2 x
ans =
2.lim √ 1−x
2
x →0
limit(sqrt(1-x^2), x, 0, 'right')
ans =
1
(x+ 3)
2. lim 2
x→−1 x −9
ans =
-1/3
ans =
-1/3
2
x +5 x−36
3. lim 2
x →0 x −16
ans =
9/4
ans =
9/4
DIFFERENTIATION
MATLAB provides the diff command for computing symbolic derivatives. In its simples form, you pass the function you
want differntiate to diff commands as an arguments.
Function Derivative
Ca.x Ca.x.ln c.a(ln is natural logarithm)
ex
lnx 1/x
lncz 1/x.lnc
xx Xx(1+lnx)
Sin(x) Cos(x)
Cos(x) -sin(x)
Tan(x) Sec2(x), or 1/cos2(x) or 1+tan2(x)
Cot(x) -csc2(x),or 1/sin2(x) or 1+cot2(x)
Sec(x) Sec(x).tan(x)
Csc(x) -csc(x).cot(x)
>>Syms x c a
>>diff(c^(a*x))
ans =
a*c^(a*x)*log(c)
>> diff(log(x))
ans =
1/x
>> y=exp(x);
>> diff(exp(x))
ans =
exp(x)
>> diff(log10(x))
ans =
1/(x*log(10))
>> diff(x^(x))
ans =
x*x^(x - 1) + x^x*log(x)
>> diff(sin(x))
ans =
cos(x)
>> diff(cos(x))
ans =
-sin(x)
>> diff(tan(x))
ans =
tan(x)^2 + 1
>> diff(cot(x))
ans =
- cot(x)^2 - 1
>> diff(sec(x))
ans =
sin(x)/cos(x)^2
>> diff(sec(x))
ans =
sin(x)/cos(x)^2
>> diff(csc(x))
ans =
-cos(x)/sin(x)^2
>> syms x
>> diff(1/x)
ans =
-1/x^2
>> diff(exp(x/2))
ans =
exp(x/2)/2
>> diff((1+x)/(1-x))
ans =
>> diff(log(sin(2*x)))
ans =
(2*cos(2*x))/sin(2*x)
>> diff(x^(tan(x)))
ans =
ans =
>> diff(log(x+sqrt(x^2+1)))
ans =
>>
INTEGRATION
Integration deals with two essentially different types of problems. In the first type, derivative of a function is
given and we want to find the function. Therefore, we basically reverse the process of differentiation. This
reverse process is known as anti-differentiation, or finding the primitive function, or finding an indefinite
integral.
The second type of problems involve adding up a very large number of very small quantities and then taking a
limit as the size of the quantities approaches zero, while the number of terms tend to infinity. This process leads
to the definition of the definite integral.
Definite integrals are used for finding area, volume, center of gravity, moment of inertia, work done by a force,
and in numerous other applications.
Finding Indefinite Integral Using MATLAB
By definition, if the derivative of a function f(x) is f'(x), then we say that an indefinite integral of f'(x) with
respect to x is f(x). For example, since the derivative (with respect to x) of x2 is 2x, we can say that an
indefinite integral of 2x is x2.
In symbols:
f'(x2) = 2x, therefore,
∫ 2xdx = x2.
Indefinite integral is not unique, because derivative of x2 + c, for any value of a constant c, will also be 2x.
This is expressed in symbols as:
∫ 2xdx = x2 + c.
Where, c is called an 'arbitrary constant'.
MATLAB provides an int command for calculating integral of an expression. To derive an expression for the
indefinite integral of a function, we write:
int(f);
Find the following integrals:
∫ secxCosecxdx
>> syms x
>> pretty(int(sec(x)*csc(x)))
log(tan(x))
>> int(sec(x)*csc(x))
ans =
log(tan(x))
∫ xcosxdx
>> pretty(int(x*cos(x)))
cos(x) + x sin(x)
∫ cos −1 2 xdx
>> pretty(int(acos(2*x)))
2
sqrt(1 - 4 x )
x acos(2 x) - --------------
2
Find the following integrals
1
∫ dx,
√ x2 +1
>> pretty(int(1/(sqrt(x^2+1))))
asinh(x)
ln ( x)
∫ √x
dx ,
>> pretty(int(log(x)/(sqrt(x))))
2 sqrt(x) (log(x) - 2)
1
∫ ( 2+ x ) √1+ x dx ,
>> pretty(int(1/(2+x)*sqrt(1+x)))
2 sqrt(x + 1) - 2 atan(sqrt(x + 1))
∫ x 2 √1+ x 4 dx
>> pretty(int((x^2*sqrt(1+x^4))))
/
| 2 4
| x sqrt(x + 1) dx
/
Finding Definite Integral Using MATLAB
By definition, definite integral is basically the limit of a sum. We use definite integrals to find areas such as the
area between a curve and the x-axis and the area between two curves. Definite integrals can also be used in
other situations, where the quantity required can be expressed as the limit of a sum.
The int command can be used for definite integration by passing the limits over which you want to calculate the
integral.
To calculate
we write,
int(x, a, b)
Find the following integrals
2
∫ ( 2 x−x 3 ) dx ,
0
>> syms x
>> int((2*x-x^3),0,2)
ans =
0
1
∫ x 3 √1+2 x 2 dx,
0
>> int(x^3*sqrt(1+2*x^2),0,1)
ans =
3^(1/2)/5 + 1/30
π /4
dx
∫ 1−sinx
0
>> int(1/(1-sin(x)),0,pi/4)
ans =
2^(1/2)
Find the area under the curve: f(x) = x2 cos(x) for −4 ≤ x ≤ 9.
>> syms x
>> f=x^2*cos(x);
>> ezplot(f,[-4,9])
>> a=int(f,-4,9)
a=
8*cos(4) + 18*cos(9) + 14*sin(4) + 79*sin(9)
>> disp('Area:'),disp(double(a))
Area:
0.3326
Calculate the area enclosed between the x-axis, and the curve y = x3−2x+5 and the ordinates x = 1 and x =
2.
>> syms x
>> y=x^3-2*x+5;
>> ezplot(y,[1,2])
>> a=(int(y,1,2))
a=
23/4
>> disp('area:'),disp(double(a))
area:
5.7500
Jana Bhawana Campus, Godawari-11
Practical file record, BCA Second semester
Mathematics-II- CAMT 154
Name of student:
Differential Equation
1. Use the dsolve command to find solution of the first-order linear nonhomogeneous
differential equation,
dy 2
=x
dx
>> syms x
>> dsolve('Dy = x^2', 'x')
ans =
x^3/3 + C3
3
x
i.e. y= + c3
3
where c3 is constant
2. Use the dsolve command to find solution of the first-order linear nonhomogeneous
differential equation,
dy 2
+ y=x
dx
>> syms x
>> dsolve('Dy - y = x^2', 'x')
ans =
C4*exp(x) - 2*x - x^2 - 2
i.e. y C 4 e x 2 x x 2 2
where C4 is a constant
dy 2
= y sinx
dx
>> syms x y
ans =
-1/(C2 - cos(x))
1
i.e y=
cosx −c 2
where C2 is a constant
dy 2
2 ( y−1 ) =3 x +4 x+1 with the initial condition of y0 1.
dx
>> syms x y
>> dsolve('2*(y-1)*Dy = 3*x^2+4*x+2', 'y(0) = -1', 'x')
ans =
1 - (x^3 + 2*x^2 + 2*x + 4)^(1/2)
i.e y 1 x 3 2 x 2 2 x 4
5. Use the method of integrating factor to solve the firstorder linear homogeneous
differential equation,
dy
−3 y=0
dx
>> syms x y
>> dsolve('Dy - 3*y = 0', 'x')
ans =
C4*exp(3*x)
6. Find solution of the first-order differential equation,
( 2 xy−sec 2 x ) dx + ( x 2 +2 y ) dy=0
>> syms x y
>> dsolve('Dy = -(2*x*y-sec(x)^2)/(x^2+2*y)', 'x');
>> simple(ans)
ans =
((4*sin(x))/cos(x) - 4*C9 + x^4 + 4*i)^(1/2)/2 - x^2/2 - ((4*sin(x))/cos(x) - 4*C9 + x^4 +
4*i)^(1/2)/2 - x^2/2