SlideShare a Scribd company logo
1 of 40
A practical work of Matlab
Bachelor in computer application (BCA)
JANA BHAWANA CAMPUS
Godavari Municipality, 11-Lalitpur
Project work submitted for the partial fulfillment of BCA Program
Tribhuwan University, Practical Examination 2076
Project Prepare by External Examiner
Name: Signatures:
Roll. No: Internal Examiners:
Faculty: BCA Name:
Semester: 2nd Signature:
Acknowledgement
We must take this opportunity to acknowledgement our sincerely gratitude to the Jana Bhawana
Campus for providingthis type of goldenopportunity by providingquality educationin the field of the
c programming which help student to build and broaden the basis concept of c programming
In addition, we would like to thank and express our gratitude to our c programming lab teachers Mr.
………………………………………….. for being our supervisor and helping us by providing valuable idea and
suggestion to perform various types of programming in c language.
Table of Contents
MATLAB........................................................................................................................................ 5
Basic Matlab...................................................................................................................................5
Matlab as a calculator to perform simple arithmetic operations:....................................................5
Addition.......................................................................................................................................... 5
Matlab recognizes variables......................................................................................................... 6
Some Commands in Matlab......................................................................................................... 7
Algebraic Simplification/ Expand ............................................................................................... 8
Limit and continuity...................................................................................................................... 19
Derivatives of exponential, logarithmic, and trigonometric function........................................... 23
Maxima and minima ..................................................................................................................... 30
Integrate and its application.......................................................................................................... 32
Some graph..................................................................................................................................35
A
MATLAB
MATLAB is a fourth-generation programming language and numerical analysis
environment.
Uses for MATLAB include matrix calculations, developing and running algorithms,
creating user interfaces (UI) and data visualization. The multi-paradigm numerical computing
environment allows developers to interface with programs developed in different languages,
which makes it possible to harness the unique strengths of each language for various purposes.
MATLAB is used by engineers and scientists in many fields such as image and signal
processing, communications, control systems for industry, smart grid design, robotics as well as
computational finance.
Cleve Moler, a professor of Computer Science at the University of New Mexico, created
MATLAB in the 1970s to help his students. MATLAB's commercial potential was identified by
visiting engineer Jack little in 1983. Moler, Little and Steve Bangart founded MathWorks and
rewrote MATLAB in C under the auspices of their new company in 1984.
Basic Matlab
Introduction
MATLAB is a fourth-generation programming language and numerical analysis environment.
Uses of MATLAB include matrix calculation, development and running algorithms, creating
user interfaces (UI) and data visualization. The multi-paradigm numerical computing
environment allows developers to interface with programs develops in different languages,
which makes it possible to harness the unique strengths of each language for various purposes.
MATLAB is used by engineers and scientists in many fields such as image and signal
processing, communications, control systems for industry, smart grid design, robotics as well
computational finance.
Matlabas a calculatorto performsimplearithmeticoperations:
Addition
i) 5+7
ii) ans+15
Solution (Using Matlab)
>> 5+7
ans =
12
>>ans+15
ans =
27
a) Subtraction, multiplication and division
i) 12-81
ii) ans-sin(pi/6)
iii) ans*11
iv) ans/2
v) ans/sqrt(169)
Solution (Using Matlab)
>> 12-81
ans =
-69
>>ans-sin(pi/6)
ans =
-69.5000
>>ans*11
ans =
-764.5000
>>ans/2
ans =
-382.2500
>>ans/sqrt(169)
ans =
-29.4038
Matlab recognizes variables
a) find the value of y if y=mx+c where m= 7, x= 8 and c= 2.
b) find the acceleration of a bike which runs at a speed of 4m/s in 5 seconds where
acceleration =
velocity
time
Solution (Using Matlab)
a) >> m=7;
>> x=8;
>> c=2;
>> y=m*x+c
y =
58
b) >> velocity=4;
time=5;
acceleration=velocity/time
acceleration =
0.8000
Some Commands in Matlab
a) Format long 2.6789765
>>format long
2.6789765
ans =
2.678976500000000
b) Format short 2.6789765
>>format short
>> 2.6789765
ans =
2.6790
c) Format bank 2.6789765
>>format bank
>> 2.6789765
ans =
2.68
d) Format long e 9841468343
>>format long e
>> 9841468343
ans =
9.841468343000000e+09
e) Format short e 9841468343
>>format short e
>> 9841468343
ans =
9.8415e+09
f) Format rat 2.345, pi
>>format rat
>> 2.345
ans =
469/200
>>format rat
>>pi
ans =
355/113
Algebraic Simplification/ Expand
a) Simplify sec2x- tan2x
>> simplify (sec(x)^(2)-tan(x)^(2))
ans =
1
b) Expand (a-2)3
>>syms a
>> expand ((a-2)^3)
ans =
a^3 - 6*a^2 + 12*a - 8
c) Expand (2x+3y)2
>>syms x y
>>expand((2*x-3*y)^2)
ans =
4*x^2 - 12*x*y + 9*y^2
SolvingQuadraticand Simultaneous LinearEquations
a) 2x2-5x+3=0
>>syms x
>> solve (2*x^2-5*x+3==0)
ans =
1
3/2
b) Solve for x and y in the pair of equation:
2x-3y=-11
X+4y=22
>>syms x y
eq1=2*x-3*y==-11;
eq2=x+4*y==22;
sol=solve([eq1,eq2],[x,y]);
xvalue=sol.x
xvalue =
2
>>yvalue=sol.y
yvalue =
5
Graph Plotting
a) Plot a graph for y=3x+5
>> x=[-2:5];
>> y=3*x+5;
>> plot(y)
b) Plot a scatter for y=3x+5
>> x=[-2:2:6];
y=3*x+5;
plot(y)
x=[-2,6];
y=3*x+5;
scatter(x,y)
c) Y= -x (range of x 0:10:100)
>> x=[0:10:100];
y =-(x);
>>plot(x,y)
d) Y=x2
x = [0:10:100];
y = x.^2;
>>plot (x,y)
e) Y=x3
>> x = [-100:10:100];
y = x.^3;
plot (x,y)
f) Y=sinx (range of x: -4pi to 4pi)
x= [-4*pi:4*pi];
>> y= sin(x);
>>plot (x,y)
g) Combine y=sinx and y=cosx in the same plot
>> x=[-4*pi:4*pi];
>> y1=sin(x);
>>plot(x,y1)
>> hold on
>> y2=cos(x);
>>plot(x,y2)
>> hold off
CompositeandInverseFunctions
a) f=2x+1; g= 2x-1; find fog, gof, fof and fog
>>syms x
>> f=2*x+1;
>> g=2*x-1;
>>compose(f,g)
ans =
4*x - 1
>>compose(g,f)
ans =
4*x + 1
>>compose(f,f)
ans =
4*x + 3
>>compose(g,g)
ans =
4*x – 3
b) Find the inverse of x, 2x2-1
>>syms x
>> f=x;
>>finverse(f)
ans =
x
c)
>>syms x
>> f=2*(x^2)-1
f =
2*x^2 - 1
>>finverse(f)
ans =
(2^(1/2)*(x + 1)^(1/2))/2
Conic section
a) Plot a circle with center (2,3) and radius 5
>>viscircles([2,3],5)
b) Plot a ellipse with equation:
π‘₯2
16
+
𝑦2
9
= 1
>>ezplot('x^2/16+y^2/9=1')
c) Plot a parabola with equation: y=8x2 [x value -10, 10]
>> x= [-10:10];
>> y= 8*x.^2;
>>plot (x,y)
Matrices, Determinant and Vector
a) A=[
1 2 5
0 βˆ’1 3
7 4 2
], B= [
2 2 6
0 βˆ’1 βˆ’3
6 4 2
]
Find A+B, B*A, A’, determinant of A, A inverse
>> A=[1 2 5;0 -1 3;7 4 2]
A =
1 2 5
0 -1 3
7 4 2
>> B=[2 2 6;0 -1 -3;6 4 2]
B =
2 2 6
0 -1 -3
6 4 2
>> A+B
ans =
3 4 11
0 -2 0
13 8 4
>> B*A
ans =
44 26 28
-21 -11 -9
20 16 46
>> A*B
ans =
32 20 10
18 13 9
26 18 34
>> A'
ans =
1 0 7
2 -1 4
5 3 2
>>inv(A)
ans =
-2/9 16/63 11/63
1/3 -11/21 -1/21
1/9 10/63 -1/63
>>det(A)
ans =
63
1) Vector a= (2,4,4) and vector b=(1,2,2)
a) Find modulus of vector a
a= [2 4 4];
>> b= [1 2 2];
>>norm(a)
ans =
6
b) Find a unit vector perpendicular to vector b
b =[1 2 2];
>> b/norm(b)
ans =
0.3333 0.6667 0.6667
c) a.b
>> a= [2 4 4];
b= [1 2 2];
>> dot (a,b)
ans =
18
d) axb
>> a= [2 4 4];
b= [1 2 2];
>> cross (a,b)
ans =
0 0 0
e) Also show that axb and bxa are not equal to each other
a= [2,4,4];
b= [1,1,1];
>> cross (a,b)
ans =
0 2 -2
>> cross (b,a)
ans =
0 -2 2
Limit and continuity
MATLAB provides the limit function for calculating limits. In its most basic form, the limit
function takes expression as an argument and finds the limit of the expression as the independent
variable goes to zero.
1. Evaluate lim
π‘₯β†’3
π‘₯ + 5
>> syms x
>> limit(x+5,3)
ans =
8
2. Evaluate lim
π‘₯β†’0
(π‘₯3
+ 5)/(π‘₯4
+ 7)
>> syms x
>> limit ((x^3+5)/(x^4+7))
ans =
5/7
3. Evaluate lim
π‘₯β†’1
( π‘₯ βˆ’ 3)/(π‘₯ βˆ’ 1)
>> syms x
limit ((x-3)/(x-1),1)
ans =
NaN
4. Algebraic limit theorem provides some basic properties of limits. These are as follow:
lim
π‘₯→𝑝
(𝑓( π‘₯) + 𝑔( π‘₯)) = lim
π‘₯→𝑝
𝑓(π‘₯) + lim
π‘₯→𝑝
𝑔(π‘₯)
lim
π‘₯→𝑝
(𝑓( π‘₯) βˆ’ 𝑔( π‘₯)) = lim
π‘₯→𝑝
𝑓(π‘₯) - lim
π‘₯→𝑝
𝑔(π‘₯)
lim
π‘₯→𝑝
(𝑓( π‘₯). 𝑔( π‘₯)) = lim
π‘₯→𝑝
𝑓(π‘₯). lim
π‘₯→𝑝
𝑔(π‘₯)
lim
π‘₯→𝑝
(𝑓( π‘₯)/𝑔( π‘₯)) = lim
π‘₯→𝑝
𝑓(π‘₯)/ lim
π‘₯→𝑝
𝑔(π‘₯)
Let us consider two functions:
F(x)=(3x+5)/(x-3) g(x)=x2+1.
Let us calculated the limits of the functions as x tends to 4, of both functions and verify the basic
properties of limits using these two functions and Matlab.
>> syms x
>> f=(3*x+5)/(x-3);
>> g=x^2+1;
>> l1=limit(f,4)
l1 =
17
>> l2=limit(g,4)
l2 =
17
>> add=limit(f+g,4)
add =
34
>>sub=limit(f-g,4)
sub =
0
>> Mult=limit(f*g,4)
Mult =
289
>> div=limit(f/g,4)
div =
1
5. Find left hand limit and right hand limit of f(x)=(x-3)/| π‘₯ βˆ’ 3|
lim
π‘₯β†’3
𝑓(π‘₯)
>> f=(x-3)/abs(x-3);
>> ezplot(f,[-1,5]);
>> l=limit(f,x,3,'left')
l =
-1
>> r=limit(f,x,3,'right')
r =
1
Derivative
MATLAB provides the diff command for computing symbolic derivatives. In its simplest form,
you pass the function you want to differentiate to diff command as an argument.
1. Compute the derivative of the function f(x)=3x2+2x-2.
>> syms x
>> f=3*x^2+2*x-2;
>> diff(f)
ans =
6*x + 2
Derivatives of exponential, logarithmic, and trigonometric function
1.
Function Derivative
Ca.x Ca.x.In c.a(In is natural logarithm)
ex ex
In x 1/x
Incx 1/x.Inc
Xx XX.(1+In x)
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
>> y=exp(x)
y =
exp(x)
>> diff(y)
ans =
exp(x)
>> y=sin(x)
y =
sin(x)
>> diff(y)
ans =
cos(x)
>> y=cos(x);
>> diff(y)
ans =
-sin(x)
>> y=tan(x);
>> diff(y)
ans =
tan(x)^2 + 1
>> y=sec(x);
>> diff(y)
ans =
sin(x)/cos(x)^2
>> y=cot(x);
>> diff(y)
ans =
- cot(x)^2 - 1
>> y=csc(x);
>> diff(y)
ans =
-cos(x)/sin(x)^2
>> syms x c
>> syms a
>> y=c^(a*x)
y =
c^(a*x)
>> diff(y)
ans =
a*c^(a*x)*log(c)
>> diff(log(x))
ans =
1/x
>> syms x;
>> diff(log10(x))
ans =
1/(x*log(10))
2. F(x)=3x+5
>> syms x;
f=3*x+5;
diff(f)
ans =
3
3. Y=(a+√ π‘₯) (a-√ π‘₯)
>> y=(a+x^(1/2)*(a-(x)^(1/2)));
>> diff(y)
ans =
(a - x^(1/2))/(2*x^(1/2)) - Β½
4. Find y'' if y=(2x+)/(x-1)
>> syms x
>> y=(2*x+1)/(x-1);
>> a=diff(y)
a =
2/(x - 1) - (2*x + 1)/(x - 1)^2
>> diff(a)
ans =
(2*(2*x + 1))/(x - 1)^3 - 4/(x - 1)^2
>> diff(y,2)
ans =
(2*(2*x + 1))/(x - 1)^3 - 4/(x - 1)^2
5. Find the 3rd order derivative of f(x)=5x4-3x2+5
>> syms x;
>> f=inline(5*x^4-3*x^2+5)
f =
Inline function:
f(x) = x.^2.*-3.0+x.^4.*5.0+5.0
>> diff(f(x),3)
ans =
120*x
6. Find the derivation of f(x)=x3-3x2+3x and plot in graph.
>> syms x
>> f=x^3-3*x^2+3*x;
>> ezplot(f,[0,2]);
>> diff(f)
ans =
3*x^2 - 6*x + 3
Preety(y)
2
3x-6x+3
7. Define the following mathematical function in Matlab using the inline command:
g(y)=2sin(piy)+3ycos(piy)
>> g=inline('2*sin(p*y)+3*y*cos(pi*y)','y')
g =
Inline function:
g(y) = 2*sin(p*y)+3*y*cos(pi*y)
8. In Exercise 7 above, differentiation the function g with respect to y.
syms y
>> diff(g(y),'y')
ans=
3*cos(pi*y)+2*pi*cos(pi*y)-3*y*pi*sin(pi*y)
Maxima and minima
If we are searching for the local maxima and minima for a graph, we are basically looking for the
highest or lowest points on the graph of the function at a particular locality, or for a particular
range of values of the symbolic variable.
For a function y=f(x) the point on the graph where the graph has zero slope are called stationary
points. In other words stationary points are where f'(x)=0.
To find the stationary points of a function we differentiate, we need to set the derivative equal to
zero and solve the equation.
1. Find the maxima n minima of y=2x3+3x2-12x+17.
>> syms x
>> y=2*x^3+3*x^2-12*x+17;
>> ezplot(y,[-2,2]);
g=diff(y)
g =
6*x^2 + 6*x – 12
s=solve(g)
s =
-2
1
>> subs(y,-2),subs(y,1)
ans =
37
ans =
10
Integrate and its application
Integration deals with two essentially different types of problems.
In the first types, 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 integration.
The second type of problems involves 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
tends to infinity. This process leads to the definition of the function of the definite integral.
Definite integrals are use for finding area, volume, center of gravity, moment if inertial, work
done by a force, and in numerous their applications.
1. Integrate: ∫
1
π‘Ž2+π‘₯2
𝑑π‘₯
>> syms a x;
int(1/(a^2+x^2))
ans =
atan(x/a)/a
2. Integrate:∫ 𝑠𝑒𝑐π‘₯ 𝑑π‘₯
syms x;
int(sec(x))
ans =
log(1/cos(x)) + log(sin(x) + 1)
3. Integrate:∫ π‘₯ 𝑒 π‘₯
𝑑π‘₯
>> syms x;
int(x*exp(x))
ans =
exp(x)*(x - 1)
4. Evaluate: ∫(5π‘₯ + 3)/( π‘₯ + 1)( π‘₯ βˆ’ 3) 𝑑π‘₯
>> syms x;
int(5*x+3)/(x+1)*(x-3)
ans =
(x*(5*x + 6)*(x - 3))/(2*(x + 1))
5. Evaluate:∫
1
(1+√ π‘₯)4 𝑑π‘₯
1
0
>> syms x;
f=1/(1+x^(1/2))^4;
int(f,0,1)
ans =
1/6
6. Evaluate: ∫ 1 + 𝑠𝑖𝑛π‘₯ 𝑑π‘₯
1
0
>> syms x;
f=1/(1+sin(x));
int(f,0,pi/2)
ans =
1
7. Evaluate: ∫ 1/π‘₯21
0
𝑑π‘₯
>> syms x;
f=1/x^(1/2);
int(f,0,1)
ans =
2
8. Evaluate: ∫ 2 sin( πœ‹π‘¦) + 3π‘¦π‘π‘œπ‘ ( πœ‹π‘¦) 𝑑π‘₯
1
0
>> syms y;
f=2*sin(pi*y) +3*y*cos(pi*y);
int(f,0,1)
ans =
(2*(2*pi - 3))/pi^2
9. Find the Taylor series expansion for the function cos x up to eight terms.
>> taylor(cos(x),x,8)
ans =
cos(8) + (sin(8)*(x - 8)^3)/6 - (sin(8)*(x - 8)^5)/120 - sin(8)*(x - 8) - (cos(8)*(x - 8)^2)/2 +
(cos(8)*(x - 8)^4)/24
10. Find the Taylor series expansion for the function ex up to nine terms.
>> taylor(exp(x),x,9)
ans =
exp(9) + exp(9)*(x - 9) + (exp(9)*(x - 9)^2)/2 + (exp(9)*(x - 9)^3)/6 + (exp(9)*(x - 9)^4)/24 +
(exp(9)*(x - 9)^5)/120
Some graph
1. Plot sinx/x (-1,1)
>> f=sin(x)/x
f =
sin(x)/x
>> ezplot(f,-1,1)
2. Plot: sinx/x2 (-1,1)
>> f=sin(x)/x^2;
>> ezplot(f,-1,1)
3. Plot: x2 (-2,2)
>> ezplot(x^2,[-2,2])
4. Plot: 6-2x-x2(-5,3)
>> ezplot(6-2*x-x^2,[-5,3])
Linear Programming Problem
1. Solve the system : maxf= 7x1+5x2
Subject to x1+2x2≀6, 4x1+3x2≀6,x1β‰₯0,x2β‰₯0.
>> f=[-7;-5];
b=[6;6;0;0];
A=[1 2; 4 3; -1 0; 0 -1];
[x,fmin]=linprog(f,A,b)
Optimal solution found.
x =
1.5000
0
fmin =
-10.5000
Hence, fmax=10.5 at x1=1.5 and x2=0.
2. Find the roots of the following simultaneous equations using the Gauss-seidel method.
20π‘₯ + 𝑦 βˆ’ 2𝑧 = 17
3π‘₯ + 20𝑦 βˆ’ 𝑧 = βˆ’18
2π‘₯ βˆ’ 3𝑦 + 20𝑧 = 25
>> f1=@(x,y,z) (1/20)*(17-y+2*z)
f1 =
function_handle with value:
@(x,y,z)(1/20)*(17-y+2*z)
>> f2=@(x,y,z) (1/20)*(-18-3*x+z)
f2 =
function_handle with value:
@(x,y,z)(1/20)*(-18-3*x+z)
>> f3=@(x,y,z) (1/20)*(25-2*x+3*z)
f3 =
function_handle with value:
@(x,y,z)(1/20)*(25-2*x+3*z)
>> x=0; y=0; z=0;
>> for i=1:5
f1(x,y,z);
f2(x,y,z);
f3(x,y,z);
x=f1(x,y,z);
y=f2(x,y,z);
z=f3(x,y,z);
end
>> x
x =
1.0342
>> y
y =
-0.9877
>> z
z =
1.3488

More Related Content

What's hot

Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlabaman gupta
Β 
Assignment problem branch and bound.pptx
Assignment problem branch and bound.pptxAssignment problem branch and bound.pptx
Assignment problem branch and bound.pptxKrishnaVardhan50
Β 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchHema Kashyap
Β 
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycleBacktracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cyclevarun arora
Β 
Mid term examination -2011 class viii
Mid term examination -2011 class viiiMid term examination -2011 class viii
Mid term examination -2011 class viiiAsad Shafat
Β 
Advanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsAdvanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsRay Phan
Β 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesShameer Ahmed Koya
Β 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arraysAmeen San
Β 
Java final project of scientific calcultor
Java final project of scientific calcultorJava final project of scientific calcultor
Java final project of scientific calcultorMd. Eunus Ali Rupom
Β 
03 eac proj vest mat módulo 1 função exponencial
03 eac proj vest mat módulo 1 função exponencial03 eac proj vest mat módulo 1 função exponencial
03 eac proj vest mat módulo 1 função exponencialcon_seguir
Β 
AN APPLICATION OF Gd -METRIC SPACES AND METRIC DIMENSION OF GRAPHS
AN APPLICATION OF Gd -METRIC SPACES AND METRIC DIMENSION OF GRAPHSAN APPLICATION OF Gd -METRIC SPACES AND METRIC DIMENSION OF GRAPHS
AN APPLICATION OF Gd -METRIC SPACES AND METRIC DIMENSION OF GRAPHSFransiskeran
Β 
Network and Tree in Graph Theory
Network and Tree in Graph TheoryNetwork and Tree in Graph Theory
Network and Tree in Graph TheoryRabin BK
Β 

What's hot (14)

Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
Β 
Assignment problem branch and bound.pptx
Assignment problem branch and bound.pptxAssignment problem branch and bound.pptx
Assignment problem branch and bound.pptx
Β 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star search
Β 
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycleBacktracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Β 
Mid term examination -2011 class viii
Mid term examination -2011 class viiiMid term examination -2011 class viii
Mid term examination -2011 class viii
Β 
Advanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsAdvanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & Scientists
Β 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
Β 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
Β 
Java final project of scientific calcultor
Java final project of scientific calcultorJava final project of scientific calcultor
Java final project of scientific calcultor
Β 
Backtracking
BacktrackingBacktracking
Backtracking
Β 
03 eac proj vest mat módulo 1 função exponencial
03 eac proj vest mat módulo 1 função exponencial03 eac proj vest mat módulo 1 função exponencial
03 eac proj vest mat módulo 1 função exponencial
Β 
AN APPLICATION OF Gd -METRIC SPACES AND METRIC DIMENSION OF GRAPHS
AN APPLICATION OF Gd -METRIC SPACES AND METRIC DIMENSION OF GRAPHSAN APPLICATION OF Gd -METRIC SPACES AND METRIC DIMENSION OF GRAPHS
AN APPLICATION OF Gd -METRIC SPACES AND METRIC DIMENSION OF GRAPHS
Β 
Network and Tree in Graph Theory
Network and Tree in Graph TheoryNetwork and Tree in Graph Theory
Network and Tree in Graph Theory
Β 
Vb.net class notes
Vb.net class notesVb.net class notes
Vb.net class notes
Β 

Similar to A practical work of matlab

Introduction of MatLab
Introduction of MatLab Introduction of MatLab
Introduction of MatLab Imran Nawaz
Β 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptxaboma2hawi
Β 
Matlab_Simulink_Tutorial.ppt
Matlab_Simulink_Tutorial.pptMatlab_Simulink_Tutorial.ppt
Matlab_Simulink_Tutorial.pptPrasenjitDey49
Β 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introductionVikash Jakhar
Β 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfahmed8651
Β 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingDr. Manjunatha. P
Β 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
Β 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordLakshmi Sarvani Videla
Β 
Matlab 1
Matlab 1Matlab 1
Matlab 1asguna
Β 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptxraghav415187
Β 
R programming lab 1 - jupyter notebook
R programming lab   1 - jupyter notebookR programming lab   1 - jupyter notebook
R programming lab 1 - jupyter notebookAshwini Mathur
Β 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersMurshida ck
Β 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd Esa
Β 
Applied numerical methods lec2
Applied numerical methods lec2Applied numerical methods lec2
Applied numerical methods lec2Yasser Ahmed
Β 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABAli Ghanbarzadeh
Β 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlabTUOS-Sam
Β 

Similar to A practical work of matlab (20)

Introduction of MatLab
Introduction of MatLab Introduction of MatLab
Introduction of MatLab
Β 
R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
Β 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
Β 
Matlab_Simulink_Tutorial.ppt
Matlab_Simulink_Tutorial.pptMatlab_Simulink_Tutorial.ppt
Matlab_Simulink_Tutorial.ppt
Β 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Β 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdf
Β 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processing
Β 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
Β 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
Β 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab Record
Β 
Matlab 1
Matlab 1Matlab 1
Matlab 1
Β 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
Β 
R programming lab 1 - jupyter notebook
R programming lab   1 - jupyter notebookR programming lab   1 - jupyter notebook
R programming lab 1 - jupyter notebook
Β 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
Β 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
Β 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
Β 
Applied numerical methods lec2
Applied numerical methods lec2Applied numerical methods lec2
Applied numerical methods lec2
Β 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLAB
Β 
Mat lab
Mat labMat lab
Mat lab
Β 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlab
Β 

Recently uploaded

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
Β 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
Β 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
Β 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
Β 
18-04-UA_REPORT_MEDIALITERAΠ‘Y_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAΠ‘Y_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAΠ‘Y_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAΠ‘Y_INDEX-DM_23-1-final-eng.pdfssuser54595a
Β 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
Β 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
Β 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
Β 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
Β 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
Β 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
Β 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
Β 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
Β 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
Β 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
Β 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
Β 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
Β 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
Β 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
Β 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at πŸ”9953056974πŸ”
Model Call Girl in Bikash Puri  Delhi reach out to us at πŸ”9953056974πŸ”Model Call Girl in Bikash Puri  Delhi reach out to us at πŸ”9953056974πŸ”
Model Call Girl in Bikash Puri Delhi reach out to us at πŸ”9953056974πŸ”
Β 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
Β 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
Β 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
Β 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
Β 
18-04-UA_REPORT_MEDIALITERAΠ‘Y_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAΠ‘Y_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAΠ‘Y_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAΠ‘Y_INDEX-DM_23-1-final-eng.pdf
Β 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
Β 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
Β 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
Β 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
Β 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
Β 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
Β 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
Β 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
Β 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
Β 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
Β 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
Β 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Β 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
Β 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
Β 

A practical work of matlab

  • 1. A practical work of Matlab Bachelor in computer application (BCA) JANA BHAWANA CAMPUS Godavari Municipality, 11-Lalitpur Project work submitted for the partial fulfillment of BCA Program Tribhuwan University, Practical Examination 2076 Project Prepare by External Examiner Name: Signatures: Roll. No: Internal Examiners: Faculty: BCA Name: Semester: 2nd Signature:
  • 2. Acknowledgement We must take this opportunity to acknowledgement our sincerely gratitude to the Jana Bhawana Campus for providingthis type of goldenopportunity by providingquality educationin the field of the c programming which help student to build and broaden the basis concept of c programming In addition, we would like to thank and express our gratitude to our c programming lab teachers Mr. ………………………………………….. for being our supervisor and helping us by providing valuable idea and suggestion to perform various types of programming in c language.
  • 3. Table of Contents MATLAB........................................................................................................................................ 5 Basic Matlab...................................................................................................................................5 Matlab as a calculator to perform simple arithmetic operations:....................................................5 Addition.......................................................................................................................................... 5 Matlab recognizes variables......................................................................................................... 6 Some Commands in Matlab......................................................................................................... 7 Algebraic Simplification/ Expand ............................................................................................... 8 Limit and continuity...................................................................................................................... 19 Derivatives of exponential, logarithmic, and trigonometric function........................................... 23 Maxima and minima ..................................................................................................................... 30 Integrate and its application.......................................................................................................... 32 Some graph..................................................................................................................................35
  • 4. A
  • 5. MATLAB MATLAB is a fourth-generation programming language and numerical analysis environment. Uses for MATLAB include matrix calculations, developing and running algorithms, creating user interfaces (UI) and data visualization. The multi-paradigm numerical computing environment allows developers to interface with programs developed in different languages, which makes it possible to harness the unique strengths of each language for various purposes. MATLAB is used by engineers and scientists in many fields such as image and signal processing, communications, control systems for industry, smart grid design, robotics as well as computational finance. Cleve Moler, a professor of Computer Science at the University of New Mexico, created MATLAB in the 1970s to help his students. MATLAB's commercial potential was identified by visiting engineer Jack little in 1983. Moler, Little and Steve Bangart founded MathWorks and rewrote MATLAB in C under the auspices of their new company in 1984. Basic Matlab Introduction MATLAB is a fourth-generation programming language and numerical analysis environment. Uses of MATLAB include matrix calculation, development and running algorithms, creating user interfaces (UI) and data visualization. The multi-paradigm numerical computing environment allows developers to interface with programs develops in different languages, which makes it possible to harness the unique strengths of each language for various purposes. MATLAB is used by engineers and scientists in many fields such as image and signal processing, communications, control systems for industry, smart grid design, robotics as well computational finance. Matlabas a calculatorto performsimplearithmeticoperations: Addition i) 5+7 ii) ans+15 Solution (Using Matlab) >> 5+7 ans = 12 >>ans+15 ans = 27 a) Subtraction, multiplication and division i) 12-81
  • 6. ii) ans-sin(pi/6) iii) ans*11 iv) ans/2 v) ans/sqrt(169) Solution (Using Matlab) >> 12-81 ans = -69 >>ans-sin(pi/6) ans = -69.5000 >>ans*11 ans = -764.5000 >>ans/2 ans = -382.2500 >>ans/sqrt(169) ans = -29.4038 Matlab recognizes variables a) find the value of y if y=mx+c where m= 7, x= 8 and c= 2. b) find the acceleration of a bike which runs at a speed of 4m/s in 5 seconds where acceleration = velocity time Solution (Using Matlab) a) >> m=7; >> x=8; >> c=2; >> y=m*x+c
  • 7. y = 58 b) >> velocity=4; time=5; acceleration=velocity/time acceleration = 0.8000 Some Commands in Matlab a) Format long 2.6789765 >>format long 2.6789765 ans = 2.678976500000000 b) Format short 2.6789765 >>format short >> 2.6789765 ans = 2.6790 c) Format bank 2.6789765 >>format bank >> 2.6789765 ans = 2.68 d) Format long e 9841468343 >>format long e >> 9841468343 ans = 9.841468343000000e+09 e) Format short e 9841468343 >>format short e >> 9841468343
  • 8. ans = 9.8415e+09 f) Format rat 2.345, pi >>format rat >> 2.345 ans = 469/200 >>format rat >>pi ans = 355/113 Algebraic Simplification/ Expand a) Simplify sec2x- tan2x >> simplify (sec(x)^(2)-tan(x)^(2)) ans = 1 b) Expand (a-2)3 >>syms a >> expand ((a-2)^3) ans = a^3 - 6*a^2 + 12*a - 8 c) Expand (2x+3y)2 >>syms x y >>expand((2*x-3*y)^2) ans = 4*x^2 - 12*x*y + 9*y^2 SolvingQuadraticand Simultaneous LinearEquations a) 2x2-5x+3=0 >>syms x
  • 9. >> solve (2*x^2-5*x+3==0) ans = 1 3/2 b) Solve for x and y in the pair of equation: 2x-3y=-11 X+4y=22 >>syms x y eq1=2*x-3*y==-11; eq2=x+4*y==22; sol=solve([eq1,eq2],[x,y]); xvalue=sol.x xvalue = 2 >>yvalue=sol.y yvalue = 5
  • 10. Graph Plotting a) Plot a graph for y=3x+5 >> x=[-2:5]; >> y=3*x+5; >> plot(y) b) Plot a scatter for y=3x+5 >> x=[-2:2:6]; y=3*x+5; plot(y) x=[-2,6]; y=3*x+5; scatter(x,y) c) Y= -x (range of x 0:10:100) >> x=[0:10:100]; y =-(x); >>plot(x,y)
  • 11. d) Y=x2 x = [0:10:100]; y = x.^2; >>plot (x,y) e) Y=x3 >> x = [-100:10:100]; y = x.^3; plot (x,y)
  • 12. f) Y=sinx (range of x: -4pi to 4pi) x= [-4*pi:4*pi]; >> y= sin(x); >>plot (x,y)
  • 13. g) Combine y=sinx and y=cosx in the same plot >> x=[-4*pi:4*pi]; >> y1=sin(x); >>plot(x,y1) >> hold on >> y2=cos(x); >>plot(x,y2) >> hold off CompositeandInverseFunctions a) f=2x+1; g= 2x-1; find fog, gof, fof and fog >>syms x >> f=2*x+1; >> g=2*x-1; >>compose(f,g) ans = 4*x - 1 >>compose(g,f) ans = 4*x + 1 >>compose(f,f) ans =
  • 14. 4*x + 3 >>compose(g,g) ans = 4*x – 3 b) Find the inverse of x, 2x2-1 >>syms x >> f=x; >>finverse(f) ans = x c) >>syms x >> f=2*(x^2)-1 f = 2*x^2 - 1 >>finverse(f) ans = (2^(1/2)*(x + 1)^(1/2))/2 Conic section a) Plot a circle with center (2,3) and radius 5
  • 15. >>viscircles([2,3],5) b) Plot a ellipse with equation: π‘₯2 16 + 𝑦2 9 = 1 >>ezplot('x^2/16+y^2/9=1') c) Plot a parabola with equation: y=8x2 [x value -10, 10] >> x= [-10:10];
  • 16. >> y= 8*x.^2; >>plot (x,y) Matrices, Determinant and Vector a) A=[ 1 2 5 0 βˆ’1 3 7 4 2 ], B= [ 2 2 6 0 βˆ’1 βˆ’3 6 4 2 ] Find A+B, B*A, A’, determinant of A, A inverse >> A=[1 2 5;0 -1 3;7 4 2] A = 1 2 5 0 -1 3 7 4 2 >> B=[2 2 6;0 -1 -3;6 4 2] B = 2 2 6 0 -1 -3 6 4 2 >> A+B ans =
  • 17. 3 4 11 0 -2 0 13 8 4 >> B*A ans = 44 26 28 -21 -11 -9 20 16 46 >> A*B ans = 32 20 10 18 13 9 26 18 34 >> A' ans = 1 0 7 2 -1 4 5 3 2 >>inv(A) ans = -2/9 16/63 11/63 1/3 -11/21 -1/21 1/9 10/63 -1/63 >>det(A) ans = 63 1) Vector a= (2,4,4) and vector b=(1,2,2) a) Find modulus of vector a a= [2 4 4];
  • 18. >> b= [1 2 2]; >>norm(a) ans = 6 b) Find a unit vector perpendicular to vector b b =[1 2 2]; >> b/norm(b) ans = 0.3333 0.6667 0.6667 c) a.b >> a= [2 4 4]; b= [1 2 2]; >> dot (a,b) ans = 18 d) axb >> a= [2 4 4]; b= [1 2 2]; >> cross (a,b) ans = 0 0 0 e) Also show that axb and bxa are not equal to each other a= [2,4,4]; b= [1,1,1]; >> cross (a,b) ans = 0 2 -2 >> cross (b,a) ans = 0 -2 2
  • 19. Limit and continuity MATLAB provides the limit function for calculating limits. In its most basic form, the limit function takes expression as an argument and finds the limit of the expression as the independent variable goes to zero. 1. Evaluate lim π‘₯β†’3 π‘₯ + 5 >> syms x >> limit(x+5,3) ans = 8 2. Evaluate lim π‘₯β†’0 (π‘₯3 + 5)/(π‘₯4 + 7) >> syms x >> limit ((x^3+5)/(x^4+7)) ans = 5/7 3. Evaluate lim π‘₯β†’1 ( π‘₯ βˆ’ 3)/(π‘₯ βˆ’ 1) >> syms x limit ((x-3)/(x-1),1) ans = NaN 4. Algebraic limit theorem provides some basic properties of limits. These are as follow: lim π‘₯→𝑝 (𝑓( π‘₯) + 𝑔( π‘₯)) = lim π‘₯→𝑝 𝑓(π‘₯) + lim π‘₯→𝑝 𝑔(π‘₯)
  • 20. lim π‘₯→𝑝 (𝑓( π‘₯) βˆ’ 𝑔( π‘₯)) = lim π‘₯→𝑝 𝑓(π‘₯) - lim π‘₯→𝑝 𝑔(π‘₯) lim π‘₯→𝑝 (𝑓( π‘₯). 𝑔( π‘₯)) = lim π‘₯→𝑝 𝑓(π‘₯). lim π‘₯→𝑝 𝑔(π‘₯) lim π‘₯→𝑝 (𝑓( π‘₯)/𝑔( π‘₯)) = lim π‘₯→𝑝 𝑓(π‘₯)/ lim π‘₯→𝑝 𝑔(π‘₯) Let us consider two functions: F(x)=(3x+5)/(x-3) g(x)=x2+1. Let us calculated the limits of the functions as x tends to 4, of both functions and verify the basic properties of limits using these two functions and Matlab. >> syms x >> f=(3*x+5)/(x-3); >> g=x^2+1; >> l1=limit(f,4) l1 = 17 >> l2=limit(g,4) l2 = 17 >> add=limit(f+g,4) add =
  • 21. 34 >>sub=limit(f-g,4) sub = 0 >> Mult=limit(f*g,4) Mult = 289 >> div=limit(f/g,4) div = 1 5. Find left hand limit and right hand limit of f(x)=(x-3)/| π‘₯ βˆ’ 3| lim π‘₯β†’3 𝑓(π‘₯) >> f=(x-3)/abs(x-3); >> ezplot(f,[-1,5]);
  • 22. >> l=limit(f,x,3,'left') l = -1 >> r=limit(f,x,3,'right') r = 1 Derivative
  • 23. MATLAB provides the diff command for computing symbolic derivatives. In its simplest form, you pass the function you want to differentiate to diff command as an argument. 1. Compute the derivative of the function f(x)=3x2+2x-2. >> syms x >> f=3*x^2+2*x-2; >> diff(f) ans = 6*x + 2 Derivatives of exponential, logarithmic, and trigonometric function 1. Function Derivative Ca.x Ca.x.In c.a(In is natural logarithm) ex ex In x 1/x Incx 1/x.Inc Xx XX.(1+In x) 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 >> y=exp(x) y = exp(x) >> diff(y)
  • 24. ans = exp(x) >> y=sin(x) y = sin(x) >> diff(y) ans = cos(x) >> y=cos(x); >> diff(y) ans = -sin(x) >> y=tan(x); >> diff(y)
  • 25. ans = tan(x)^2 + 1 >> y=sec(x); >> diff(y) ans = sin(x)/cos(x)^2 >> y=cot(x); >> diff(y) ans = - cot(x)^2 - 1 >> y=csc(x); >> diff(y) ans = -cos(x)/sin(x)^2 >> syms x c >> syms a >> y=c^(a*x)
  • 26. y = c^(a*x) >> diff(y) ans = a*c^(a*x)*log(c) >> diff(log(x)) ans = 1/x >> syms x; >> diff(log10(x)) ans = 1/(x*log(10)) 2. F(x)=3x+5 >> syms x; f=3*x+5; diff(f) ans =
  • 27. 3 3. Y=(a+√ π‘₯) (a-√ π‘₯) >> y=(a+x^(1/2)*(a-(x)^(1/2))); >> diff(y) ans = (a - x^(1/2))/(2*x^(1/2)) - Β½ 4. Find y'' if y=(2x+)/(x-1) >> syms x >> y=(2*x+1)/(x-1); >> a=diff(y) a = 2/(x - 1) - (2*x + 1)/(x - 1)^2 >> diff(a) ans = (2*(2*x + 1))/(x - 1)^3 - 4/(x - 1)^2 >> diff(y,2) ans =
  • 28. (2*(2*x + 1))/(x - 1)^3 - 4/(x - 1)^2 5. Find the 3rd order derivative of f(x)=5x4-3x2+5 >> syms x; >> f=inline(5*x^4-3*x^2+5) f = Inline function: f(x) = x.^2.*-3.0+x.^4.*5.0+5.0 >> diff(f(x),3) ans = 120*x 6. Find the derivation of f(x)=x3-3x2+3x and plot in graph. >> syms x >> f=x^3-3*x^2+3*x; >> ezplot(f,[0,2]);
  • 29. >> diff(f) ans = 3*x^2 - 6*x + 3 Preety(y) 2 3x-6x+3 7. Define the following mathematical function in Matlab using the inline command: g(y)=2sin(piy)+3ycos(piy) >> g=inline('2*sin(p*y)+3*y*cos(pi*y)','y') g =
  • 30. Inline function: g(y) = 2*sin(p*y)+3*y*cos(pi*y) 8. In Exercise 7 above, differentiation the function g with respect to y. syms y >> diff(g(y),'y') ans= 3*cos(pi*y)+2*pi*cos(pi*y)-3*y*pi*sin(pi*y) Maxima and minima If we are searching for the local maxima and minima for a graph, we are basically looking for the highest or lowest points on the graph of the function at a particular locality, or for a particular range of values of the symbolic variable. For a function y=f(x) the point on the graph where the graph has zero slope are called stationary points. In other words stationary points are where f'(x)=0. To find the stationary points of a function we differentiate, we need to set the derivative equal to zero and solve the equation. 1. Find the maxima n minima of y=2x3+3x2-12x+17. >> syms x >> y=2*x^3+3*x^2-12*x+17; >> ezplot(y,[-2,2]);
  • 31. g=diff(y) g = 6*x^2 + 6*x – 12 s=solve(g) s = -2 1 >> subs(y,-2),subs(y,1) ans =
  • 32. 37 ans = 10 Integrate and its application Integration deals with two essentially different types of problems. In the first types, 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 integration. The second type of problems involves 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 tends to infinity. This process leads to the definition of the function of the definite integral. Definite integrals are use for finding area, volume, center of gravity, moment if inertial, work done by a force, and in numerous their applications. 1. Integrate: ∫ 1 π‘Ž2+π‘₯2 𝑑π‘₯ >> syms a x; int(1/(a^2+x^2)) ans = atan(x/a)/a
  • 33. 2. Integrate:∫ 𝑠𝑒𝑐π‘₯ 𝑑π‘₯ syms x; int(sec(x)) ans = log(1/cos(x)) + log(sin(x) + 1) 3. Integrate:∫ π‘₯ 𝑒 π‘₯ 𝑑π‘₯ >> syms x; int(x*exp(x)) ans = exp(x)*(x - 1) 4. Evaluate: ∫(5π‘₯ + 3)/( π‘₯ + 1)( π‘₯ βˆ’ 3) 𝑑π‘₯ >> syms x; int(5*x+3)/(x+1)*(x-3) ans = (x*(5*x + 6)*(x - 3))/(2*(x + 1)) 5. Evaluate:∫ 1 (1+√ π‘₯)4 𝑑π‘₯ 1 0 >> syms x; f=1/(1+x^(1/2))^4; int(f,0,1) ans =
  • 34. 1/6 6. Evaluate: ∫ 1 + 𝑠𝑖𝑛π‘₯ 𝑑π‘₯ 1 0 >> syms x; f=1/(1+sin(x)); int(f,0,pi/2) ans = 1 7. Evaluate: ∫ 1/π‘₯21 0 𝑑π‘₯ >> syms x; f=1/x^(1/2); int(f,0,1) ans = 2 8. Evaluate: ∫ 2 sin( πœ‹π‘¦) + 3π‘¦π‘π‘œπ‘ ( πœ‹π‘¦) 𝑑π‘₯ 1 0 >> syms y; f=2*sin(pi*y) +3*y*cos(pi*y); int(f,0,1)
  • 35. ans = (2*(2*pi - 3))/pi^2 9. Find the Taylor series expansion for the function cos x up to eight terms. >> taylor(cos(x),x,8) ans = cos(8) + (sin(8)*(x - 8)^3)/6 - (sin(8)*(x - 8)^5)/120 - sin(8)*(x - 8) - (cos(8)*(x - 8)^2)/2 + (cos(8)*(x - 8)^4)/24 10. Find the Taylor series expansion for the function ex up to nine terms. >> taylor(exp(x),x,9) ans = exp(9) + exp(9)*(x - 9) + (exp(9)*(x - 9)^2)/2 + (exp(9)*(x - 9)^3)/6 + (exp(9)*(x - 9)^4)/24 + (exp(9)*(x - 9)^5)/120 Some graph 1. Plot sinx/x (-1,1) >> f=sin(x)/x f = sin(x)/x >> ezplot(f,-1,1)
  • 36. 2. Plot: sinx/x2 (-1,1) >> f=sin(x)/x^2; >> ezplot(f,-1,1) 3. Plot: x2 (-2,2) >> ezplot(x^2,[-2,2])
  • 37. 4. Plot: 6-2x-x2(-5,3) >> ezplot(6-2*x-x^2,[-5,3]) Linear Programming Problem 1. Solve the system : maxf= 7x1+5x2 Subject to x1+2x2≀6, 4x1+3x2≀6,x1β‰₯0,x2β‰₯0.
  • 38. >> f=[-7;-5]; b=[6;6;0;0]; A=[1 2; 4 3; -1 0; 0 -1]; [x,fmin]=linprog(f,A,b) Optimal solution found. x = 1.5000 0 fmin = -10.5000 Hence, fmax=10.5 at x1=1.5 and x2=0. 2. Find the roots of the following simultaneous equations using the Gauss-seidel method. 20π‘₯ + 𝑦 βˆ’ 2𝑧 = 17 3π‘₯ + 20𝑦 βˆ’ 𝑧 = βˆ’18 2π‘₯ βˆ’ 3𝑦 + 20𝑧 = 25 >> f1=@(x,y,z) (1/20)*(17-y+2*z) f1 = function_handle with value: @(x,y,z)(1/20)*(17-y+2*z) >> f2=@(x,y,z) (1/20)*(-18-3*x+z)
  • 39. f2 = function_handle with value: @(x,y,z)(1/20)*(-18-3*x+z) >> f3=@(x,y,z) (1/20)*(25-2*x+3*z) f3 = function_handle with value: @(x,y,z)(1/20)*(25-2*x+3*z) >> x=0; y=0; z=0; >> for i=1:5 f1(x,y,z); f2(x,y,z); f3(x,y,z); x=f1(x,y,z); y=f2(x,y,z); z=f3(x,y,z); end >> x
  • 40. x = 1.0342 >> y y = -0.9877 >> z z = 1.3488