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

Experiment-1&2 21BCH045

The lab report details two experiments conducted in a computational software environment, focusing on matrix operations and numerical differentiation. The first experiment involves creating matrices, performing basic arithmetic operations, and plotting trigonometric functions, while the second experiment applies the finite difference method to derive and compare numerical and analytical derivatives of a polynomial function. MATLAB code is provided for both experiments, along with results and graphs illustrating the findings.

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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views9 pages

Experiment-1&2 21BCH045

The lab report details two experiments conducted in a computational software environment, focusing on matrix operations and numerical differentiation. The first experiment involves creating matrices, performing basic arithmetic operations, and plotting trigonometric functions, while the second experiment applies the finite difference method to derive and compare numerical and analytical derivatives of a polynomial function. MATLAB code is provided for both experiments, along with results and graphs illustrating the findings.

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 PDF, TXT or read online on Scribd
You are on page 1/ 9

Process Modeling and Optimization

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.

𝑎1 𝑎2 𝑏1 𝑏2 𝑎 + 𝑏1 𝑎2 + 𝑏2
[𝑎 𝑎4 ] + [𝑏3 ]= [ 1 ]
3 𝑏4 𝑎3 + 𝑏3 𝑎4 + 𝑏4

II. Subtraction of Matrix

In matrix subtraction, the corresponding elements of two matrices are


subtracted to determine the difference between them.

𝑎1 𝑎2 𝑏1 𝑏2 𝑎 − 𝑏1 𝑎2 − 𝑏2
[𝑎 𝑎4 ] − [𝑏3 ]= [ 1 ]
3 𝑏4 𝑎3 − 𝑏3 𝑎4 − 𝑏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.

𝑎1 𝑎2 𝑏1 𝑏2 𝑎 ∗ 𝑏 + 𝑎2 ∗ 𝑏3 𝑎1 ∗ 𝑏2 + 𝑎2 ∗ 𝑏4
[𝑎 𝑎4 ] ∗ [𝑏3 ]= [ 1 1 ]
3 𝑏4 𝑎3 ∗ 𝑏1 + 𝑎4 ∗ 𝑏3 𝑎3 ∗ 𝑏2 + 𝑎4 ∗ 𝑏4
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.

𝑑𝑓(𝑥) 𝑓(𝑥 + ℎ) − 𝑓(𝑥)


𝑓 ′ (𝑥) = = lim
𝑑𝑥 ℎ→0 ℎ

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 𝑓(𝑥) 𝑓(𝑥 + ℎ) − 2 ∗ 𝑓(𝑥) − 2 ∗ 𝑓(𝑥 − ℎ)


𝑓 ′′ (𝑥) = 2
= lim
𝑑𝑥 ℎ→0 ℎ2

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy