INTRODUCTION TO MATHEMATICAL
SOFTWARE
(Mathematica and Matlab)
The most popular mathematical software are MATLAB and Mathematica. The
website for this software system are MATLAB (www.mathworks.com), and
Mathematica (www.wolfram.com). There are many other mathematical
software systems. But each of these systems has its own syntax. As per the
demand of course, two software MATLAB and Mathematica are introduced.
MATHEMATICA
Mathematica is a mathematical software package that can be used by any
member of the Engineering Department. This seminar will show you what
Mathematica can do and will let you asses how useful it could be to you.
Mathematica is a huge package with far more features than can be covered in a
single afternoon. However, the seminar will show you the basics of entering
problems and obtaining and displaying results. It will also show you how to
explore the package for yourself and find the things that you are interested in.
The majority of the seminar is devoted to giving you real hands-on experience
in using Mathematica. The main driving philosophy behind Mathematica is to
produce a mathematical software package that is as close as possible to doing
mathematics with a pen and paper. This shows itself in two ways. The
appearance resembles normal mathematical text much closer than a program
using a conventional programming language. You can easily use mathematical
symbols like integral signs and Greek characters can be used in variable names.
You can include explanatory text, with titles and subsections that make a
Mathematica notebook look more like a document than a program. However,
the most important features of Mathematica is that it can perform algebraic
mathematics in addition to numerical mathematics. Computers mostly do
numerical calculations. So for example, the expression y=x^2 takes the number
x and squares it, and puts the value into y. Using computational algebra the
result y is a symbolic expression that can be manipulated algebraically,
differentiated, and integrated using the same rules you use to manipulate
equations.
1
Arithmetic Operations in Mathematics
Symbols Operations
+ Plus
- Minus
Space or * Multiply
/ Divide
^ Power
Some Mathematical Functions
Sqrt[x] √
Exp[x]
Log[x]
Log[a, x]
Sin[x],Cos[x],Tan[x] sin x, cos x, tan x
Abs[x] | |, absolute value
Mod[m, n] m modulo n
Pi Pi
E e
2
The Four Kinds of Brackets in Mathematics
Parentheses for grouping
(term)
f[x] Square brackets for functions
{a, b, c} Curly braces for list
A[[i]] Double brackets for indexing (Part[a,i])
Using Mathematica, we can calculate exact value of expression which has more than 10 (in general
electronic calculator) places after decimal. Mathematica can handle numbers of any size.
End you input with // N.
It gives approximate value.
Relational and Logical Operations
x==y equal
x! = y or x unequal
x greater than
x > = y or x y greater than or equal to
x<y less than
x < = y or x y Less than or equal to
3
ACKNOWLEDGEMENT
This report is specially designed to develop and enhance the knowledge of students in Mathematica
and MATLAB Software.
I would like to express my sincere gratitude to my subject teacher ‘Kamal Prasad Bhatta‘ and the
whole faculty of Humanities and Social Sciences who gave me this opportunity to fulfill this report.
He gave me moral support and guided me in different matters regarding the topics. He had been very
kind and patient while suggesting me the outlines. I thank him for his overall support.
I am also thankful to everyone who supported me, for that I have completed my report effectively and
moreover on time. They gave me many helpful comments which helped me a lot in preparing it.
Thankyou!
4
Lab-1
Limit and continuity
1) Evaluate:
In[1]= [ ]
Out[1]=
2) Evaluate:
In[2]= [ ]
Out[2]= 36
√
3) Evaluate:
In[1]= [ √ ⁄ ]
Out[1]= √
√
4) Evaluate:
√
In[2]= [( √ )⁄(√ ) ]
Out[2]=
5) Evaluate:
In[3]= [ ⁄ ]
Out[3]=
6) Evaluate:
In[5]= [ ⁄ ]
Out[5]=
7) Evaluate: √ √
In[6]= [(√ √ ) ]
Out[6]=
8) Evaluate:
In[7]= [ [ ]⁄ ]
Out[7] =
9) Evaluate:
In[8]= [ [ ]⁄ [ ] ]
5
Out[8]=
10) Evaluate:
In[13]= [ [ ] ⁄ [ ] ]
Out[13]= 1
11)
In[14]= [ [ ] [ ] ⁄ ⁄ ⁄ ]
Out[14]= √
6
Lab-2
Construction of graphs
1) f(x) = x^2 at [-2,2]
In[4]= [ { }]
4
Out[4]= 2 1 1 2
2) f(x)= 6-2x-x^2 at [-5,3]
In[5]= [ { }]
4 2 2
Out[5]=
3) f(x)= x^3 at [-1,1]
In[7]= [ { }]
1.0
0.5
1.0 0.5 0.5 1.0
0.5
1.0
Out[7]=
7
4) f(x)= -2x^3+6x^2-3 at [-5.,5]
In[8]= [ { }]
200
100
4 2 2 4
100
Out[8]=
5) f(x)= x^4-2x^2 at [-10,10]
In[9]= [ { }]
10000
8000
6000
4000
2000
Out[9]= 10 5 5 10
6) f(x)= x^4-4x^3+10 at [-10,12]
In[10]= [ { }]
14000
12000
10000
8000
6000
4000
2000
Out[10]= 10 5 5 10
8
7) f(x)= at [-1,1]
In[12]= [{ [ [ ]⁄ { }]}]
1.00
0.95
0.90
0.85
Out[12]= 1.0 0.5 0.5 1.0
8) f(x)= at [-1,1]
In[13]= [{ [ [ ]⁄ { }]}]
10
1.0 0.5 0.5 1.0
10
Out[13]=
9
Lab-3
Differentiation
Find the derivative and the following w.r.t x.
1) y = 2x+5
In[8]:= [ ]
Out[8]=
2) y = √
In[9]:= [ [ ] ]
Out[9]=
√
3) y = 7x^10+5x^2-6
In[10]:= [ ]
Out[10]=
4) y = (7x^2+3x)*(7x^2-x)
In[12]:= [ ]
Out[12]=
5) y =
In[13]:= [ [ ] ]
Out[13]= [ ]
6) y =
In[14]:= [ [ ] ]
Out[14]= [ ]
7) y =
In[15]:= [ [ ] ]
Out[15]= [ ]
8) y =
In[17]:= [ [ ] ]
Out[17]= [ ] [ ]
9) y = sec x
In[14]:= [ [ ] ]
Out[14]= [ ] [ ]
10) y = cot x
In[17]:= [ [ ] ]
Out[17]= [ ]
10
11) y =
In[25]:= [ [ ] ]
Out[25]=
12) y =
In[26]:= [ [ ] ]
Out[26]=
13) y = √
In[28]:= [√ ]
Out[28]=
√
14) y = sin3x
In[33]:= [ [ ] ]
Out[33]= [ ]
15) y = sin^2x
In[1]:= [ [ ] ]
Out[1]= [ ] [ ]
11
Lab-4
Integration & its application
Integrate the following:
1) ∫
In[14]= [ ]
Out[14]=
2) ∫ dx
In[15]= [ ]
Out[15]=
3) ∫ √
In[16]=Sqrt[1 + Cos[x]], x]
Out[16]=2 Sqrt[2] Sin[x/2] + C *)
4) ∫
In[17]=Integrate[Sin[x], x]
Out[17]= −cos x+ C
5) ∫
In[18]= Integrate[Cos[x], x]
Out[18]= sinx +C
6) ∫
[ ] [ [ ] [ ] ]
Out[19]= secx+C\sec x + Csecx+C
7) ∫
In[20]= Integrate[x + 4, {x, 0, 2}]
Out[20]= 10
8) ∫
In[21]= Integrate[Sin[x], {x, 0, Pi}]
Out[21]=2
9) ∫
In[22]= Integrate[2 x / (x^2 + 1), {x, 0, 1}]
Out[22]=2
10) ∫ √
In[23]= Integrate[Sqrt[16 - x^2], {x, 0, 4}]
Out[23]=8
12
11) ∫
In[24]= Integrate[1/(x^2 + 1), {x, 0, Infinity}]
Out[24]= π/2
12) ∫
√
In[24]= Integrate[1/Sqrt[x], {x, 0, 1}]
Out[24]=2
13) ∫
In[25]= Integrate[1/(1 + x^2), {x, -Infinity, Infinity}]
Out[25]= π
14) ∫
In[26]= Integrate[Exp[x], x]
Out[26]= ex+C
15) ∫
In[26]= Integrate[1/x, x]
Out[26]= ln∣x∣+C
MATLAB
13
Lab-5
Linear Programming Problem/ Matrix
1) Maximum f= 7
Subject to +2
Solution:
>> f= [-7; -5];
>> b= [6; 6; 0; 0];
>> A= [1 2; 4 3; -1 0; 0 -1];
>> [x, f_min] = linprog (f, A, b)
Optimization terminated.
x=
1.5000
0.0000
f_min =
-10.5000
2) Maximize Z= x + y
Subject to the constraints,
2x + y
Solution:
>> f= [-1; -1];
>> b= [14; 10; 0; 0];
>> A= [2 1; 1 2; -1 0; 0 -1];
>> [x, f_min] = linprog (f, A, b)
Optimization terminated.
x=
6.0000
2.0000
f_min =
-8.0000
14
3) Solve by matrix method:
x + y + z=9, 2x + 5y+ 7z=52, 2x+y-z=0
Solution:
>> A= [1 1 1; 2 5 7; 2 1 -1];
>> b= [ 9 52 0]';
>> X=A \ b
X=
4) Solve by matrix method:
-2x+2y+z= -4
-8x+7y-4z= -47
9x-8y+5z= 55
Solution:
>> A= [-2 2 1; -8 7 -4; 9 -8 5];
>> b= [ -4 -47 55]';
>> X= A \ b
X=
3.0000
-1.0000
4.0000
15
Lab-6
Bisection & Newton-Raphson method
1) Using method of bisection, find the square root of equation lying
between 1 & 2 correct to 3 places of decimals.
Solution:
>> f= @ (x) x^3-x-4;
>> a=1;
>> b=2;
>> tol=0.001;
>> while abs(a-b)>=tol
x0= (a+b)/2
if f(a) *f(x0)<0;
b=x0;
else
a=x0;
end
root=x0
end
x0 =
1.5000
root =
1.5000
x0 =
1.7500
root =
1.7500
x0 =
1.8750
root =
1.8750
16
x0 =
1.8125
root =
1.8125
x0 =
1.7813
root =
1.7813
x0 =
1.7969
root =
1.7969
x0 =
1.7891
root =
1.7891
x0 =
1.7930
root =
1.7930
x0 =
17
1.7949
root =
1.7949
x0 =
1.7959
root =
1.7959
2) Use Newton-Raphson’s method to approximate √ with an error less than 0.00001.
Solution:
>> f = @ (x) 2^3/2;
>> Df= @ (x) 3/2 * 2^1/2
; >> x0=1;
>> tol= 0.00001;
>> diff=1;
>> while diff>=tol
x1=x0-f(x0)/Df(x0);
diff=abs(x1-x0);
x0=x1;
end
root=x0
18
Lab-7
Numerical Integration
1) Using Simpson rule , evaluate:
a) ∫ , n=4
>> f= @ (x) (1/ (1 + x^2));
>> a= 0;
>> b = 1;
>> n = 4;
>> h = (b-a) / n;
>> s = f (a) + f(b);
>> for i = 1: n-1
s= s + 4 * f (a + i * h);
end
>> for k= 2: 2: n-2;
s= s-2 * f (a + k * h);
end
>> I = (h / 3) * s
I=
0.7854
b) ∫
>> f = @ (x) sin (x);
>> a=0;
>> b=pi;
>> n=6;
>> h=(b-a)/n;
>> s= f(a) + f(b);
>> for i = 1: n-1
s = s + 4 * f (a + i *h);
end
>> for k = 2: 2: n-2;
s= s-2 *f (a + k *h);
end
>> I = (h/3) * s
I=
2.0009
C) ∫
>> f = @ (x) (x^4);
>> a=0;
>> b=5;
>> n=4;
>> h= (b-a)/n;
>> s= f(a)+ f(b);
19
>> for i = 1: n-1
s= s + 4 *f (a + i * h);
end
>> for k = 2: 2: n-2;
s = s-2 * f (a + k * h);
end
>> I = (h/3) * s
I=
626.6276
2. Using Trapezoidal rule, evaluate:
a) ∫
>> f = @ (x) sin (x);
>> a = 0;
>> b = pi;
>> n = 4;
>> h = (b-a)/n;
>> s= 0.5 * (f (a) + f (b));
>> for i = 1: n-1;
s = s + f( a + i * h);
end
>> I = h * s
I=
1.8961
b ∫
>> f = @ (x) (2 * x ^ 2 - 1);
>> a = 0;
>> b= 2;
>> n=4;
>> h = (b-a)/n;
>> s= 0.5 * (f(a) + f(b));
>> for i = 1: n-1
20
s = s + f (a + i * h);
end
>> I = h * s
I=
3.5000
c) ∫
>> f = @ (x) ( 1/ (1 + x^2));
>> a=0;
>> b=1;
>> n=2;
>> h = (b-a)/n;
>> s= 0.5 * (f(a) + f(b));
>> for i = 1: n-1
s = s + f (a + i * h);
end
>> I = h * s
I=
0.7750
21