Assignment 1
Assignment 1
tion
Lab Report
School of Energy Technology
Department of Chemical Engineering
Pandit Deendayal Energy University (PDEU)
1. Problem Statement:
2. Theory
I. Addition of Matrix
[ ][ ][
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
[ ][ ][
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
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
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:
' df (x ) f ( x +h ) −f (x )
f ( x )= =lim
dx h→0 h
3. Code (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 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