You are on page 1of 12

KC33503

CHEMICAL ENGINEERING COMPUTATION


LECTURE 2
ANALITICAL AND NUMERICAL
SOLUTION

Dr Nurhazwani Binti Yusoff Azudin


hazwaniyusoff@ums.edu.my
L.3,R.59
Solution for differential equation

Analytical Solution Numerical Solution


Pure math equation only Use iterative calculation
Solve solution for 1 value The answer can be different
The answer always correct from the actual value
Sometimes may be impossible Depends on the size of iteration
/extremely difficult to solve Easier to get close to solution
E.g: Initial value problem, Eg: Finite element method,
boundary value problem iteration
Example:

Find local minimum/max for this function

Solution (Analytical):
Example:

Find local minimum/max for this function

Solution (Analytical):

To find local min/max, set the derivative =0

Derivative of f(x);
Example:

Find local minimum/max for this function

Solution (Analytical):

To find local min/max, set the derivative =0

Derivative of f(x);

Substitude x=0 into f(x);


Example:

Find local minimum/max for this function

Solution (Numerical):
Example:

Find local minimum/max for this function

Solution (Numerical):

To find local min/max, we need to defind the x value 1st in MATLAB

x=linspace (-2,2,100);
Example:

Find local minimum/max for this function

Solution (Numerical):

To find local min/max, we need to defind the x value 1st in MATLAB

x=linspace (-2,2,100);
linspace: Generate linearly spaced vector
Syntax
y = linspace(x1,x2)
y = linspace(x1,x2,n)
Description
y = linspace(x1,x2) returns a row vector of 100 evenly spaced points between x1 and x2.
y = linspace(x1,x2,n) generates n points. The spacing between the points is (x2-x1)/(n-1).
linspace is similar to the colon operator, “:”, but gives direct control over the number of points and always includes the endpoints. “lin” in the
name “linspace” refers to generating linearly spaced values as opposed to the sibling function logspace, which generates logarithmically
spaced values.
Example:

Find local minimum/max for this function

Solution (Numerical):

To find local min/max, we need to defind the x value 1st in MATLAB

x=linspace (-2,2,100);
f=x.^2+2;

Element-wise power
Example:

Find local minimum/max for this function

Solution (Numerical):

To find local min/max, we need to defind the x value 1st in MATLAB

x=linspace (-2,2,100); ans:


f=x.^2+2; minvalue= 2.0004
plot(x,f), ylim([0,8])
grid on

minvalue=min(f)
Repeat the example by using
x=linspace (-2,2,10000)

Compare and discuss the final answer


Thank
you!!

You might also like