0% found this document useful (0 votes)
3 views9 pages

Assignment 1

The lab report details two experiments involving matrix operations and numerical differentiation using MATLAB. The first experiment focuses on creating and manipulating matrices, while the second experiment involves calculating first and second-order derivatives of a polynomial function using the finite difference method. Both experiments include problem statements, theoretical background, and MATLAB code with corresponding results and plots.

Uploaded by

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

Assignment 1

The lab report details two experiments involving matrix operations and numerical differentiation using MATLAB. The first experiment focuses on creating and manipulating matrices, while the second experiment involves calculating first and second-order derivatives of a polynomial function using the finite difference method. Both experiments include problem statements, theoretical background, and MATLAB code with corresponding results and plots.

Uploaded by

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

Process Modeling and Optimiza-

tion
Lab Report
School of Energy Technology
Department of Chemical Engineering
Pandit Deendayal Energy University (PDEU)

Name: Pratham Patel


Roll no.: 21BCH045
Semester: Seventh
Group: E3
EXPERIMENT 1: REACQUAINT WITH GUI OF
COMPUTATIONAL SOFTWARE AND BASIC
COMPUTATION

1. Problem Statement:

Write a code to create two arrays A = [2 5 7; 9 0 8] and B = [7 55 6; 23 45 67] and


perform addition, subtraction and multiplication. Also, generate a vector x ε [-5pi
5pi]. The increment is pi/100. Plot graphs of sin x, cos x, tan x, cosec x, sec x, and cot
x all in the same graphs. Make sure the graph types (dashed or symbols or colors are
all different for different graphs).

2. Theory

 Matrices are rectangular arrays of numbers arranged in rows and columns,


forming the foundation for various mathematical and computational
applications. In MATLAB, matrices are central to data manipulation, making
them indispensable for tasks ranging from basic arithmetic to advanced
engineering computations.

I. Addition of Matrix

Matrix addition is the process of adding corresponding elements of two


matrices of the same size.

[ ][ ][
a1 a2 b 1 b 2
+
a3 a4 b 3 b 4
a +b a +b
= 1 1 2 2
a3 +b 3 a 4 +b 4 ]
II. Subtraction of Matrix

In matrix subtraction, the corresponding elements of two matrices are


subtracted to determine the difference between them.

[ ][ ][
a1 a2
a3 a4
b b a −b a 2−b2
− 1 2= 1 1
b3 b 4 a 3−b3 a4 −b 4 ]
III. Multiplication of Matrix

Matrix multiplication involves multiplying the elements of the rows of


the first matrix with the elements of the columns of the second matrix,
followed by summing the products.
[ ][ ][
a1 a2 b1 b2

a3 a4 b3 b 4
a ∗b + a ∗b a 1∗b2 +a 2∗b 4
= 1 1 2 3
a 3∗b 1+ a4∗b3 a3∗b2 +a 4∗b4 ]
3. Code (Matlab):

 Creating two matrices A = [2 5 7; 9 0 8] and B = [7 55 6; 23 45 67] and


performing addition, subtraction, and multiplication

Fig 1 Showing Matlab code of addition, subtraction, and Multiplication of two


matrices

Result
Fig 2 Shows the result of the code written in fig-1

 Generating a vector x ε [-5pi 5pi]. The increment is pi/100. Plot graphs of sin
x, cos x, tan x, cosec x, sec x, and cot x all in the same graphs.
Fig-3 Showing Matlab code for plotting sin(x), cos(x), cosec(x), sec(x), tan(x),
and cot(x) at x = [-5*π, 5*π]

Result:

Fig-4 Showing all sin(x), cos(x), cosec(x), sec(x), tan(x), and cot(x) in one
graph at x = [-5*π, 5*π]
EXPERIMENT 2: FIRST AND SECOND-ORDER
NUMERICAL DIFFERENTIATION OF FUNCTIONS
USING FINITE DIFFERENCE METHOD
1. Problem Statement:

 Given f(x) = −0.1x4 − 0.15x3 − 0.5x2 − 0.25x + 1.2. Plot f, df/dx, and
d2f/dx2 in the range of x ε [-20 35] using FDE. Take step size as your final
two digits of roll number/100

Roll no,: 21BCH045


Step Size: 0.45

 For the same polynomial function plot analytical results of f, df/dx and
d2f/dx2 and compare with numerical solutions. Show your code and the
plots.

2. Theory:

1) First Principle of Derivative: The first principle of derivatives, also


known as the definition of a derivative, involves calculating the slope
of the tangent to a function at a point. This is achieved by taking the
limit of the average rate of change as the interval approaches zero.

' df (x ) f ( x +h ) −f (x )
f ( x )= =lim
dx h→0 h

2) Second Symmetric Derivative: The second-order derivative provides


information about the concavity of a function, indicating whether the
function is curving upwards or downwards. The second symmetric
derivative is calculated using the central difference method, which is a
more accurate approach compared to the forward or backward
difference methods.
2
d f (x) f ( x+ h )−2∗f ( x )−2∗f ( x−h)
f '' ( x )= 2
=lim
dx h →0 h2

3. Code (Matlab):

 Generating first and Second-order derivatives of f(x) = - 0.1*x4 - 0.15*x3 –


0.5*x2 – 0.25*x + 1.2, using the limit formula of forward derivative and
comparing it with the analytically solved derivatives of the following function,
Fig 5 Showing Code in Matlab of Experiment-2

Code in Written in matlab:

clc
clear all
x=[-20 : 0.45 : 35];
e=[-20:0.45:34.45];
h=[-20:0.45:34];
y = -0.1*x.^(4) - 0.15*x.^(3) - 0.5*x.^(2) - 0.25*x + 1.2 ;
n=size(x);
dy_dx=0;
d2y_dx=0;
for i=1:length(x)-1
dy_dx(i)=(y(i+1)-y(i))/(x(i+1)-x(i));
end
for i=1:length(x)-2
d2y_dx(i)=(y(i+2)-(2*(y(i+1)))+y(i))/((x(i+1)-x(i))^2);
end
dy=0;
d2y=0;
for i=1:length(x)
y(i)=-0.1*x(i)^(4) - 0.15*x(i)^(3) - 0.5*x(i)^(2) - 0.25*x(i) + 1.2 ;
dy(i)= -0.4*x(i)^3 -0.75*x(i)^2 - x(i) - 0.25;
d2y(i)= -1.2*x(i)^2 - 1.5*x(i) - 1;
end

plot(x,dy,'+')
hold on
plot(x,d2y,'*')
hold on
plot(e,dy_dx)
hold on
plot(x,y)
hold on
plot(h,d2y_dx,'r')

Fig-6 Showing both way calculated derivative of first-order and Second-order


derivative

Fig 7 Showing a graph of the first-order and second-order derivatives using Limit
Fig 8 Shows a graph of the first-order and second-order derivative solving analytically

You might also like