0% found this document useful (0 votes)
17 views

Matlab Odd Workbook- 2022-2023 (1)

Uploaded by

gowthamgo1745
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Matlab Odd Workbook- 2022-2023 (1)

Uploaded by

gowthamgo1745
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

MATLAB LABORATORY WORKBOOK

Subject Code : U18MAI1202L - Linear Algebra and Calculus


Regulations : R18
Class : I B.E/B.Tech Branches
Certificate

This is to certify that it is a bonafide record of practical work


done by Sri/Kum.___________________________________ bearing the Roll No.
______________ of ____________ class _______________________________________ branch in
the ____________________________ Laboratory during the academic year
___________________ under our supervision.

Faculty in charge Internal Examiner


TABLE OF CONTENTS

S.No LIST OF EXPERIMENTS Page No

1. Introduction to MATLAB

Matrix Operations - Addition, Multiplication, Transpose,


2.
Inverse

3. Rank of a matrix and solution of a system of linear equations.

Characteristic equation of a matrix and Cayley-Hamilton


4.
theorem.

5. Eigenvalues and Eigenvectors of higher order matrices

6. Curve tracing

7. Differentiation & Integration

8. Solving first and second order ordinary differential equations.

9. Determining maxima and minima of a function of one variable.

Determining maxima and minima of a function of two


10.
variables.
MATLAB - MARKS BREAK UP STATEMENT

S. Progra Execu
Viva Total Staff
No Date Name of the experiment m tion
(10) (30) sign
. (10) (10)

1 Introduction to MATLAB

Matrix Operations - Addition,


2
Multiplication, Transpose,
Inverse

Rank of a matrix and solution of


3
a system of linear equations.

Characteristic equation of a
4
matrix and Cayley-Hamilton
theorem.

Eigenvalues and Eigenvectors of


5
higher order matrices

6 Curve tracing

7 Differentiation and Integration

Solving first and second order


8
ordinary differential equations.

Determining maxima and


9
minima of a function of one
variable.
Determining maxima and
10
minima of a function of two
variables.
WORKSHEET-1

INTRODUCTION TO MATLAB

1.1 OBJECTIVES

a. To know the history and features of MATLAB


b. To know the local environment of MATLAB

1.2 Introduction
MATLAB is a high-level language and interactive environment for numerical
computation, visualization, and programming. Using MATLAB, you can analyze
data, develop algorithms, and create models and applications. The language,
tools, and built-in math functions enable you to explore multiple approaches and
reach a solution faster than with spread sheets or traditional programming
languages, such as C/C++ or Java. You can use MATLAB for a range of
applications, including signal processing and communications, image and video
processing, control systems, test and measurement, computational finance, and
computational biology. More than a million engineers and scientists in industry
and academia use MATLAB, the language of technical computing.

A matrix is a two-dimensional array of numbers.


In MATLAB, you create a matrix by entering elements in each row as comma or space
delimited numbers and using semicolons to mark the end of each row.
For example, let us create a 4-by-5 matrix a −

a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8]

MATLAB will execute the above statement and return the following result −
a =
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8

Referencing the Elements of a Matrix


To reference an element in the mth row and nth column, of a matrix mx, we write −
mx(m, n);
For example, to refer to the element in the 2nd row and 5th column, of the matrix a, as
created in the last section, we type −

a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];

a(2,5)

MATLAB will execute the above statement and return the following result −
ans = 6

To reference all the elements in the mth column we type A(:,m).


Let us create a column vector v, from the elements of the 4 th row of the matrix a −

a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];

v = a(:,4)

MATLAB will execute the above statement and return the following result −
v =
4
5
6
7

You can also select the elements in the mth through nth columns, for this we write −

a(:,m:n)

Let us create a smaller matrix taking the elements from the second and third columns −

a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];

a(:, 2:3)

MATLAB will execute the above statement and return the following result −
ans =
2 3
3 4
4 5
5 6

In the same way, you can create a sub-matrix taking a sub-part of a matrix.

a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];

a(:, 2:3)

MATLAB will execute the above statement and return the following result −
ans =
2 3
3 4
4 5
5 6

In the same way, you can create a sub-matrix taking a sub-part of a matrix.
For example, let us create a sub-matrix sa taking the inner subpart of a −
3 4 5
4 5 6

a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];

sa = a(2:3,2:4)

MATLAB will execute the above statement and return the following result −
sa =
3 4 5
4 5 6

Deleting a Row or a Column in a Matrix


You can delete an entire row or column of a matrix by assigning an empty set of square
braces [] to that row or column. Basically, [] denotes an empty array.

For example, let us delete the fourth row of a −

a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];

a( 4 , : ) = []

MATLAB will execute the above statement and return the following result −
a =
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7

Next, let us delete the fifth column of a −

a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];

a(: , 5)=[]
MATLAB will execute the above statement and return the following result −
a =
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7

Example

In this example, let us create a 3-by-3 matrix m, then we will copy the second and third
rows of this matrix twice to create a 4-by-3 matrix.
Create a script file with the following code −

a = [ 1 2 3 ; 4 5 6; 7 8 9];

new_mat = a([2,3,2,3],:)

When you run the file, it displays the following result −


new_mat =
4 5 6
7 8 9
4 5 6
7 8 9
Task 1

1. Try these commands:


>> 3*5*6

>> z1 = 34; z2 = 17; z3 = -8;

>> z1/z2

>> z1-z3

>> z2+z3-z1

2. Determine the value of the expression a(b + c(c + d))a, where a = 2, b = 3, c =


−4,d = −3.

>> a = 2; b = 3; c = -4; d = -3;


>> a*(b+c*(c+d))*a

3. Evaluate the MATLAB expression

>>1+2/3*4-5

>>1/2/3/4

>>1/2+3/4*5

>>5-2*3*(2+7)
>>(1+3)*(2-3)/3*4

>>(2-3*(4-3))*4/5

4. Calculate the expressions:


(1) sin 600 in radians

(2) sin 600 in degree

(3) elog4

(4) cos 450 - sin 450

(5) log e2

5. Create two vectors running from one to six and from six to one and then
demonstrate the use of the dot arithmetical operations: s+t, s-t, st, s/t, s2, 1/s,
s/2, s+1

s=1:6

t=6:-1:1

(i) s+t

(ii) s-t
(iii) s*t

(iv) s./t

(v) s.^2

(vi) 1./s

(vii) s./2

(ix) s+1

6. Construct the polynomial y = (x + 2)2(x3 + 1) for values of x from minus one to


one in steps of 0.1.

7. Find the roots of the polynomial y = x3 − 3x2 + 2x


WORKSHEET-2
MATRIX OPERATIONS -
ADDITION, MULTIPLICATION, TRANSPOSE, INVERSE

2.1 OBJECTIVES:

 To evaluate the addition, subtraction and multiplication of two Matrices.

 To evaluate the transpose and inverse of a Matrix.

2.2 MATRIX ADDITION

 1 2 4 0 3 6 
   
Example 1: Find the addition of the matrices A   0 5 6  and B   7 1  1 
 7 8 4  5 7  9
   

A=[1 2 4 ; 0 5 6; 7 8 4];
B=[0 3 6; 7 1 -1; 5 7 9];
disp('The matrix A= ');A
disp('The matrix B= ');B
% to find sum of a and b, c=a+b;
disp('The sum of A and B is ');
C=A+B
Output:
The matrix A=

A=

1 2 4
0 5 6
7 8 4

The matrix B=
B=

0 3 6
7 1 -1
5 7 9
The sum of A and B is

C=

1 5 10
7 6 5
12 15 13

MATRIX MULTIPLICATION:

 1 2 4 0 3 6 
   
Example 2: Find the multiplication of the matrices A   0 5 6  and B   7 1  1 
 7 8 4  5 7  9
   

A=[1 2 4 ; 0 5 6; 7 8 4];
B=[0 3 6; 7 1 -1; 5 7 9];
disp('The matrix A= ');A
disp('The matrix B= ');B
disp('The multiplication of A and B is ');
C=A*B

Output:

The matrix A=

A=

1 2 4
0 5 6
7 8 4

The matrix B=

B=

0 3 6
7 1 -1
5 7 9

The multiplication of A and B is

C=
34 33 40
65 47 49
76 57 70

MATRIX TRANSPOSE AND INVERSE.

 1 2 4
 
Example 3: Find the transpose and inverse of the matrix A   0 5 6 
 7 8 4
 

A=[1 2 4 ; 0 5 6; 7 8 4];
disp('The matrix A= ');A
% to find transpose of A;
disp('The transpose of A is ');A'
% to find inverse of A;
disp('The inverse of A is ');
inv(A)
Output:
The matrix A=
A=
1 2 4
0 5 6
7 8 4

The transpose of A is
ans =

1 0 7
2 5 8
4 6 4

The inverse of A is
ans =

0.3333 -0.2857 0.0952


-0.5000 0.2857 0.0714
0.4167 -0.0714 -0.0595
Task 2

 5 2 12 
 
1. Find the addition and subtraction of the matrices A   0 19 16  and
17 8 6 
 
 8 13 8 
 
B  15 10  1 
 5 9  9
 

 11 2 14  10 8 6 
   
2.Find the multiplication of the matrices A  10 5 60  and B   7 1  11
17 8 4   9 7 9 
   
 1 22 4 
 
3. Find the transpose and inverse of the matrix A  18 5 16 
 7 28 4 
 

 6 2 4 12 21 14 
   
4. Find the matrix multiplication of the two matrices A   8 5 6  B   11 15 36 
 7 8 4 17 68 24 
 ,  .

 91 24 42 
 
5. Find the transpose and inverse of the matrix A   18 52 48 
 72 45 64 
 
WORKSHEET-3
RANK OF A MATRIX AND SOLUTION OF A SYSTEM OF LINEAR EQUATIONS

3.1 OBJECTIVES:

 To find the rank of a matrix

 To solve the system of linear equations

 To find the echelon form of the matrix.

3.2 PROGRAM

RANK OF THE MATRIX


 1 2 3 2
 
Example 1: Find the rank of the matrices A   2 3 5 1 
1 3 4 5
 
A=[1 2 3 2; 2 3 5 1; 1 3 4 5]
disp('The matrix A= ');A
% To find rank of A
disp('The rank of A is ');
C=rank(A)

Output:
The matrix A=

A=

1 2 3 2
2 3 5 1
1 3 4 5

The rank of A is

C=

ECHELON FORM OF THE MATRIX


 1 2 3 2
 
Example 2.Find the echelon form of the matrix A   2 3 5 1 
1 3 4 5
 
A=[1 2 3 2; 2 3 5 1; 1 3 4 5]
disp('The matrix A= ');A
% to find rank of A ;
disp('The echelon form of A is ');
D=rref(A)

Output:
The matrix A=

A=

1 2 3 2
2 3 5 1
1 3 4 5

The rank of A is
C=

SOLUTION OF SYSTEM OF LINEAR EQUATIONS.

Example 3: Solving system of linear equations 2x+y+z=2; -x+y-z=3; x+2y+3z=-10.

syms x y z
eqn1 = 2*x + y + z == 2;
eqn2 = -x + y - z == 3;
eqn3 = x + 2*y + 3*z == -10;
[A,B] = equationsToMatrix([eqn1, eqn2, eqn3], [x, y, z])
X = linsolve(A,B)

Output:
A=
[ 2, 1, 1]
[ -1, 1, -1]
[ 1, 2, 3]
B=
2
3
-10

X=
3
1
-5
Task 3

 1 1 1 3
 
1. Find the rank of the matrices A   1 1  1 1 
 3 3  5 1
 

 2 1 1 1
 
2. Find the echelon form of the matrix A   1  2 1 1
 1 1  2 1

3. Solving system of linear equations


x  2y  z  4
x  3y  2z  5
2 x  y  3z  3
2 1 2 1
6  6 6 12 
4. Find the row echelon form of the matrix A   
4 3 3  3
 
2 2  1 1 

 4  5 1 2
 
5. Find the rank of the matrix A   3 1  2 9 
1 4 1 5 

6. Solving system of linear equations


x  2y  z  3
2x  3 y  2z  5
3x  5 y  5 z  2
3x  9 y  z  4
WORKSHEET-4
CHARACTERISTIC EQUATION OF A MATRIX AND CAYLEY-HAMILTON THEOREM

4.1 OBJECTIVES

 To verify Cayley Hamilton Theorem and find the inverse of the matrix
 1 3
4.2 Example 1:Verify Cayley Hamilton Theorem for the matrix A   
 2 4
Program:
A=[1 3;2 4]
disp('The matrix A= ');A
% to find the polynomial of A ;
X=poly(A)
disp('The polynomial of A is ');
round(X)
y=polyvalm(X,A)
disp(' Cayley Hamilton theorem ');
round(y)
disp('The identity matrix is ');
i=eye(2,2)
disp('The inverse of A is ');
InvA=(A-5*i)/2
s=inv(A)
Output:
The matrix A=
A=
1 3
2 4
X = 1.0000 -5.0000 -2.0000
The polynomial of A is
ans = 1 -5 -2
Cayley Hamilton theorem
ans =
0 0
0 0
The identity matrix is
i=
1 0
0 1
The inverse of A is
InvA =
-2.0000 1.5000
1.0000 -0.5000
s=
-2.0000 1.5000
1.0000 -0.5000
1 1 4 
 
Example 2:Verify Cayley Hamilton Theorem for the matrix A   3 2 1 
 2 1  1
 
Program:
A=[1 -1 4;3 2 1;2 1 -1]
disp('The matrix A= ');A
% to find the polynomial of A ;
X=poly(A)
disp('The polynomial of A is ');
round(X)
y=polyvalm(X,A)
disp(' Cayley Hamilton theorem ');
round(y)
disp('The identity matrix is ');
i=eye(3,3)
disp('The inverse of A is ');
InvA=(-A^2+2*A+7*i)/12
s=inv(A)
Output:

The matrix A=
A=
1 -1 4
3 2 1
2 1 -1
X = 1.0000 -2.0000 -7.0000 12.0000
The polynomial of A is
ans = 1 -2 -7 12
Cayley Hamilton theorem
ans =
0 0 0
0 0 0
0 0 0
The identity matrix is
i=
1 0 0
0 1 0
0 0 1
The inverse of A is
InvA = 0.2500 -0.2500 0.7500
-0.4167 0.7500 -0.9167
0.0833 0.2500 -0.4167
s = 0.2500 -0.2500 0.7500
-0.4167 0.7500 -0.9167
0.0833 0.2500 -0.4167
Task 4:

1. Verify Cayley Hamilton theorem for the matrix and find the value of A1
1 0 3 
 
A   2 1  1
 1 1 1 
 

2. Verify Cayley Hamilton theorem for the matrix and find A1 .

1 3 7
 
A   4 2 3
1 2 1
 
3. Verify Cayley Hamilton theorem for the matrix and find A1 .
1 2 3 
 
A   2 1 4 
 3 1  1
 
4 . Verify Cayley Hamilton theorem for the matrix and find A1 .
2 1 1
 
A   0 1 0
 1 1 2
 
5. Verify Cayley Hamilton theorem for the matrix and find A1 .
1 0 1
 
A  3 4 5 
0  6  7
 
WORKSHEET-5
EIGENVALUES AND EIGENVECTORS OF HIGHER ORDER MATRICES

5.1 OBJECTIVES

 To find the Eigenvalues and Eigenvectors of the matrix

5.2 Example 1: Find the eigenvalues and eigenvectors of the matrix


 1  1 0
 
A    1 2 1
 0 1 1
 
Program:
A=[1 -1 0 ; -1 2 1 ; 0 1 1]
disp(' The Eigenvalues of A are ');
eig(A)
disp(' The Eigenvector of A are ');
[v,d]=eig(A)
round([v,d])

Output:
A=
1 -1 0
-1 2 1
0 1 1
The eigenvalues of A are
ans =
0.0000
1.0000
3.0000
The Eigenvector of A are
v=
0.5774 0.7071 -0.4082
0.5774 -0.0000 0.8165
-0.5774 0.7071 0.4082
d=
0.0000 0 0
0 1.0000 0
0 0 3.0000
ans =
1 1 0 0 0 0
1 0 1 0 1 0
-1 1 0 0 0 3

Example 2: Find the eigenvalues and eigenvectors of the matrix


 1  3 2 1 
 
3 9  6 3 
B
2  6 4  2
 
 1 3  2 1 
 

Program:
B=[1 -3 2 -1 ; -3 9 -6 3 ; 2 -6 4 -2 ; -1 3 -2 1]
disp(' The Eigenvalues of B are ');
eig(B)
disp(' The Eigenvector of B are ');
[v,d]=eig(B)
round([v,d])

Output:
B=
1 -3 2 -1
-3 9 -6 3
2 -6 4 -2
-1 3 -2 1
The Eigenvalues of B are
ans =
-0.0000
-0.0000
0.0000
15.0000
The Eigenvector of B are
v=
0.0481 0.9649 0.0069 -0.2582
0.1516 0.1956 0.5820 0.7746
-0.2712 -0.1304 0.8017 -0.5164
-0.9493 0.1173 -0.1357 0.2582
d=
-0.0000 0 0 0
0 -0.0000 0 0
0 0 0.0000 0
0 0 0 15.0000
ans =
0 1 0 0 0 0 0 0
0 0 1 1 0 0 0 0
0 0 1 -1 0 0 0 0
-1 0 0 0 0 0 0 15
Task: 5

 11 4 7 

1.Find the eigenvalues and eigenvectors of A=  7 2 5 

10 4 6 
 

 2 0  1
1
 
2.Find the eigenvalues of A , given that A   0 2 0 
 1 0 2 
 
 6 2 2 
3. Compute the eigenvalues and eigenvectors of the matrix A   2 3 1
 
 2 1 3 

 4  20  10 
 
4. Find the eigenvalues and eigenvectors of A    2 10 4 
 6  30  13 
 

  2 2  3
 
5. Find the eigenvalues and eigenvectors of A   2 1  6
 1  2 0 
 
WORKSHEET-6

CURVE TRACING

6.1 OBJECTIVES
 To plot a two dimensional plot.
 To plot a three dimensional plot.

6.2 Example 1: Plot the simple function y = x for the range of values for x from 0 to
100, with an increment of 5.

x = [0:5:100];
y = x;
plot(x, y)

100

90

80

70

60

50

40

30

20

10

0
0 10 20 30 40 50 60 70 80 90 100

Example 2: Plot the function y = x2

x = [-100:20:100];
y = x.^2;
plot(x, y)
10000

9000

8000

7000

6000

5000

4000

3000

2000

1000

0
-100 -80 -60 -40 -20 0 20 40 60 80 100

Example 3: Plot the function y=sin x

x = [0:0.01:10];
y = sin(x);
plot(x, y), xlabel('x'), ylabel('Sin(x)'), title('Sin(x)
Graph'), grid on, axis equal

Sin(x) Graph

1
Sin(x)

-1

-2

-3

0 1 2 3 4 5 6 7 8 9 10
x

Example 4: Plot multiple functions on the same graph for the curve y=sin x and
g = cos x

x = [0 : 0.01: 10];
y = sin(x);
g = cos(x);
plot(x, y, x, g, '.-'), legend('sin(x)', 'cos(x)')

1
Sin(x)
0.8 Cos(x)

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7 8 9 10

Example 5. Draw the graph of two polynomials f(x) = 3x4 + 2x3+ 7x2 + 2x + 9 and
g(x) = 5x3 + 9x + 2.

x = [-10 : 0.01: 10];


y = 3*x.^4 + 2 * x.^3 + 7 * x.^2 + 2 * x + 9;
g = 5 * x.^3 + 9 * x + 2;
plot(x, y, 'r', x, g, 'g')
4
x 10
3.5

2.5

1.5

0.5

-0.5

-1
-10 -8 -6 -4 -2 0 2 4 6 8 10

x2 y2
Example 6. Plot the curve  1
4 9
ezplot('x^2/4+y^2/9=1');
axis equal;

3-D Plot

Example 7. Create a 3D surface map for the function g  xe( x  y2 )


2
.

[x,y] = meshgrid(-2:.2:2);
g = x .* exp(-x.^2 - y.^2);
surf(x, y, g)

0.5

-0.5
2
1 2

0 1
0
-1
-1
-2 -2
Task: 6
1. Plot the sine-wave curve y=sin x such that x varies from 0 to 2 with h=/100.

2. For f ( x)  8x 8  7 x 7  12 x 6  5x 5  8x 4  13x 3  12 x  9 , compute f(2),roots of f(x) and


plot for x= 0 to 20 in step of 0.1.
3. Plot the curve y = e-x sin(2x + 3);

4. Create a 3D surface map for the function g  xe ( x  y2 )


2
.

5. Plot the curve y = x3


WORKSHEET-7

DIFFRENTIATION AND INTEGRATION

7.1 OBJECTIVES:
 To do differentiation and Integration

 To differentiate:diff(x)
The ‘diff’ operator will return the difference between the n and n+1 row or
column of data if applied to an array of numbers. When applied to symbolic
variables, ‘diff’ will return the approximate derivative. The derivative, as defined
geometrically, is the tangent of a curve at a given point. When applied to a
function, the derivative returns a new function that is the tangent at every point
in the domain. Mathematically, this derivative is the infinitesimally small change
in the dependent variable from point a to a+h, over the change in h, where h
approaches 0 (similar to rise/run or slope for linear equations). The derivative of
our function f(x) is equal to cos(x).

Example 1: Find the differentiation of sin(x)

>> f=sin(x)
>> d=diff(f)
d=cos(x)
>> subs(d,pi)
ans=-1

 To Integrate:int(x)
The opposite of a derivative is the integral, or the anti-derivative, which provides the
area under a curve. The first fundamental theorem of calculus guarantees that a
continuous function will have an antiderivative, ‘int’ which allows us to both determine
the explicit and numerical solutions to an equation. We can further use ‘int’ to calculate
both the indefinite (int(f)) and definite integrals over the range of a to b (int(f,a,b)).
Let’s evaluate the integral of f(x), both based on the indefinite integral and over the
range of 0 to pi.

Example 2: Find the integration of cos(x)

>> f=cos(x)
>>ans=int(f)
ans=sin(x)
>> int(ans,0,pi/2)
ans=1

Example 3:
Just like the ‘diff’ function, we can utilize the ‘int’ function to evaluate an equation with
respect to x (dx), y (dy) or z (dz). This is specified with the 2nd argument (i.e. ‘int(g,x)’).
If a definite integral is to be performed, this can be done using 4 arguments, with limits
a to b specified (i.e. ‘int(g,y,a,b)’).
>> int(g,y)
ans =(x*y^3)/3 - y*sin(z)
>> int(g,y,0,2)
ans =(8*x)/3 - 2*sin(z)

Example 4:
We can even evaluate multiple integrals for functions with more than one variable.
While a single integral can be thought of as the area under the curve, a double integral
can be visualized as the volume underneath a surface.

1 2
Let’s take the following double integral for example:   xy dxdy
2

0 0
>>h = x*y^2;
h =x*y^2;
>> h_intx = int(h,x,0,2)
h_intx =2*y^2
>>h_doubleint int(h_intx,y,0,1)
h_doubleint= 2/3
TASK: 7

1) Compute the derivative of the function f (t )  3t 2  2t 2

2) Find the differentiation of f ( x)  18x 3  12 x 2  5x

3) Compute the derivative of cos(3x 2  2 x  1)


2 3 5
4) Integrate  xyz dxdydz
3

0 0 3

2 8
5) Find the value of  a c da dc
2 5

0 5

2 3 5
6) Compute the value of   u v
3 2
w5 dudvdw
0 0 3
WORKSHEET- 8
SOLVING FIRST AND SECOND ORDER ORDINARY DIFFERENTIAL
EQUATIONS

8.1 OBJECTIVES
 To solve the first order ordinary differential equations
 To solve the second order ordinary differential equations

dy
8.2 Example 1: Solve  5y
dx

%Solving first order ODE


s = dsolve('Dy = 5*y')
Output:
s=
C2*exp(5*t)

df
Example 2. Solve  2 f  cos t
dt
%Solving First order ODE
f= dsolve('Df = -2*f + cos(t)','t')
Output:
f=
(2*cos(t))/5 + sin(t)/5 + C4*exp(-2*t)

dx x 1 
 y 

Example 3. Solve   tan
dy 1  y 2 1 y2 
 

% LEIBNITZ'S FORM - EX2


x=dsolve('Dx+(1/(1+y^2))*x=atany/(1+y^2)','y')
Output:
x= atany - C10*exp(-atan(y))
Example 4: Solve ( D  1) y  0; y(0)  1 & y(0)  2
2

y=dsolve('D2y - y = 0','y(0) = -1','Dy(0) = 2')

Output:
y =exp(t)/2 - (3*exp(-t))/2

Example 5: Solve ( D 2  5D  6) y  e x
y=dsolve('D2y+5*Dy+6*y=exp(x)','x')

Output:
y=
exp(x)/12 + C25*exp(-2*x) + C26*exp(-3*x)

Example 6. Solve ( D 2  5D  6) y  4e  x log x

y=dsolve('D2y+5*Dy+6*y=4*exp(-x)*log(x)','x')

Output:
y=
C28*exp(-2*x) - exp(-2*x)*(4*ei(x) - 4*exp(x)*log(x)) + C29*exp(-3*x) +
exp(-3*x)*(2*ei(2*x) - 2*exp(2*x)*log(x))

Example 4. Solve ( D 3  D 2  D  1) y  e x  cos x, y(0)  y(0)  y(0)  0

y=dsolve('D3y-D2y+Dy-
y=exp(x)+cos(x)','y(0)=0','Dy(0)=0','D2y(0)=0','x')
TASK :8
 dy 
1. Solve    4 y (t )  e t , y (0)  1.
 dt 

dy
 y cot x  2 x sin x
2. Solve dx

2
 
3. Solve the differential equation D  D  1 y  0

3 2 
4. Solve the differential equation D  3D  3D  1 y  0

 4 2 
5. Solve the differential equation D  2D  1 y  0

4 3 2 2 x
6. Solve the differential equation ( D  2D  D ) y  x  e
2 x
7. Solve the differential equation ( D  1) y  e cos x

2
8. Solve the differential equation ( D  4) y  cos3x
WORKSHEET- 9
DETERMINING MAXIMA AND MINIMA OF A FUNCTION OF ONE
VARIABLE
9.1 OBJECTIVE
 To determine the maxima and minima of a function of a single variable
9.2 Example 1: Find the extreme value of the function f(x)= x3 – 12x2 – 20.
Program:
syms x
f=x^3-12*x^2-20
fx=diff(f,x)
a=solve(fx)
double(a)
fxx=diff(fx,x)
D=subs(fxx,x,8)
if D >0
disp('Attains Minima')
else
disp('Attains Maxima')
end
D=subs(fxx,x,0)
if D >0
disp('Attains Minima')
else
disp('Attains Maxima')
end
OUTPUT
f =x^3 - 12*x^2 - 20
fx = 3*x^2 - 24*x
a=0 8
fxx = 6*x - 24
D = 24 D=-24
Attains Minima Attains Maxima
Task:9
1. Find the maximum value of the function f ( x)  x 4  5x 3  3x  18

2. Find the minimum value of the function f ( x)  7 x 3  2 x 2  5


3. Find the extrema of the function f ( x)  x  3x  24 x  5
3 2

4. Find the extrema of f ( x)  x(12  2 x)


2
WORKSHEET- 10
DETERMINING MAXIMA AND MINIMA OF A FUNCTION OF TWO VARIABLES

10.1 OBJECTIVES
 To determine maxima and minima of a function of two variables.
10.2 Example 1: Find the extreme value of the function
f ( x, y)  x 4  2 y 4  12 xy 2  20 y 2 .

PROGRAM:
syms x y
f=x.^4+2*y.^4-12*x*y.^2-20*y.^2
fx=diff(f,x)
fy=diff(f,y)
[a,b]=solve(fx,fy);
double([a,b])
fxx=diff(fx,x)
fxy=diff(fx,y)
fyy=diff(fy,y)
D=fxx*fyy-(fxy)^2
D1=subs(D,[x,y],[3.6247,3.9842])
A1=subs(fxx,[x,y],[3.6247,3.9842])
D2=subs(D,[x,y],[3.6247,-3.9842])
A2=subs(fxx,[x,y],[3.6247,-3.9842])
if D1>0
if A1>0
disp('Attains Minima')
else
disp('Attains Maxima')
end
else
if D1==0
disp('No conclusion')
else
disp('Neither Minima nor Maxima')
end
end
if D2>0
if A2>0
disp('Attains Minima')
else
disp('Attains Maxima')
end
else
if D2==0
disp('no conclusion')
else
disp('Neither Minima nor maxima')
end
end
ezsurf(f,[0,5,0,5])

Output:
f =x^4 - 12*x*y^2 + 2*y^4 - 20*y^2
fx = 4*x^3 - 12*y^2
fy = 8*y^3 - 24*x*y - 40*y
ans =
0.0000 + 0.0000i 0.0000 + 0.0000i
3.6247 + 0.0000i 3.9842 + 0.0000i
3.6247 + 0.0000i -3.9842 + 0.0000i
-1.8123 - 0.9240i 1.0884 - 1.2734i
-1.8123 + 0.9240i 1.0884 + 1.2734i
-1.8123 - 0.9240i -1.0884 + 1.2734i
-1.8123 + 0.9240i -1.0884 - 1.2734i
fxx =12*x^2
fxy = -24*y
fyy = 24*y^2 - 24*x - 40
D = - 12*x^2*(- 24*y^2 + 24*x + 40) - 576*y^2
ans =
3941535027/25000000

4 2 2 4
x - 12 x y - 20 y + 2y

600

400

200

-200

5
4 5
3 4
2 3
2
1 1
0 0
y x

Example 2 :. Find the extreme value of the function


f ( x, y)  x 3  2 y 3  12 xy 2  20 y 2

Program:
syms x y
f=x.^3+2*y.^3-12*x*y.^2-20*y.^2
fx=diff(f,x)
fy=diff(f,y)
[a,b]=solve(fx,fy);
double([a,b])
fxx=diff(fx,x)
fxy=diff(fx,y)
fyy=diff(fy,y)
D=fxx*fyy-(fxy)^2
D1=subs(D,[x,y],[ -1.4815,0.7807])
A1=subs(fxx,[x,y],[ -1.4815,0.7807])
D2=subs(D,[x,y],[ -1.9048,-0.9524])
A2=subs(fxx,[x,y],[ -1.9048,-0.9524])
if D1>0
if A1>0
disp('Attains Minima')
else
disp('Attains Maxima')
end
else
if D1==0
disp('No conclusion')
else
disp('Neither Minima nor Maxima')
end
end
if D2>0
if A2>0
disp('Attains Minima')
else
disp('Attains Maxima')
end
else
if D2==0
disp('no conclusion')
else
disp('Neither Minima nor maxima')
end
end
ezsurf(f,[0,5,0,5])

Output:
f =x^3 - 12*x*y^2 + 2*y^3 - 20*y^2
fx =3*x^2 - 12*y^2
fy =6*y^2 - 24*x*y - 40*y
ans =
0 0
-1.9048 -0.9524
-1.4815 0.7407

fxx =6*x
fxy =-24*y
fyy =12*y - 24*x - 40
D =- 576*y^2 - 6*x*(24*x - 12*y + 40)
D1=-4935508323/12500000
A1 =-8889/1000
D2 =-178582143/390625
A2 =7143/625

Neither Minima nor Maxima


Neither Minima nor maxima
Task :10
1. Find the Maximum value of the function f ( x, y)  x 3  3xy 2  12 xy  2

2. Find the Minimum value of the function f ( x, y)  x 4  6 y 3  36 xy  20 y


3. Examine for extreme values of the function u ( x, y)  x 4  y 4  2 x 2  4 xy  2 y 2
4. Find the maximum and minimum values of the function
f ( x, y)  x 3  y 3  63( x  y)  12 xy
5. Find the maximum or minimum value of the function
f ( x, y)  2( x 2  y 2 )  x 4  y 4

You might also like