0% found this document useful (0 votes)
1 views38 pages

CH1004E - Module 3

The document discusses various numerical methods using C++, including the Bisection method and Newton-Raphson method for finding roots of polynomial equations. It also covers numerical integration techniques such as the Trapezoidal rule and Simpson's Rule, along with examples and practice problems. Additionally, it touches on linear regression and interpolation methods.

Uploaded by

adffgff fggg
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)
1 views38 pages

CH1004E - Module 3

The document discusses various numerical methods using C++, including the Bisection method and Newton-Raphson method for finding roots of polynomial equations. It also covers numerical integration techniques such as the Trapezoidal rule and Simpson's Rule, along with examples and practice problems. Additionally, it touches on linear regression and interpolation methods.

Uploaded by

adffgff fggg
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

CH1004E – Module 3

NUMERICAL METHODS USING C++


Finding roots of a polynomial
Bisection method
• The bisection method is a simple way to find solutions to
equations with only one unknown.
• It is a popular technique in mathematics for solving transcendental
equations.
• The Bisection Method is a numerical root-finding technique used to
solve equations that lack analytical solutions and to find the roots
of polynomial equations. It works by dividing an interval into
smaller intervals and narrowing down the range of possible
solutions iteratively.
• The bisection method is a technique used to find the solutions to
a polynomial equation. It divides the interval where the solution
exists into smaller intervals. The main idea behind this method is
that if a continuous function changes sign within an interval, there
must be a root within that interval.
Newton- Raphson method – Roots of cubic equation
Algorithm for Newton Raphson method
Trapizoidal rule for Numerical Integration
Numerical Integration
Simpson’s Rule is based on
the idea that we can find the
equation of a quadratic
through three points if we
have three points.
To get a rough estimate of
the definite integral b∫a f(x)
dx We divide the interval [a,
b] into an even number of n
subintervals, each of width
[a, b] using Simpson’s Rule.
#include <math.h>
using namespace std; // Driver program
// Function to calculate f(x) int main()
float func(float x) {
{
return log(x); float lower_limit = 4; // Lower limit
}
float upper_limit = 5.2; // Upper limit
// Function for approximate integral int n = 6; // Number of interval
float simpsons_(float ll, float ul, int n)
{ cout << simpsons_(lower_limit, upper_limit,
// Calculating the value of h n);
float h = (ul - ll) / n;
return 0;
// Array for storing value of x and f(x)
float x[10], fx[10];
}
// Calculating values of x and f(x)
for (int i = 0; i <= n; i++) {
x[i] = ll + i * h;
fx[i] = func(x[i]);
}

// Calculating result
float res = 0;
for (int i = 0; i <= n; i++) {
if (i == 0 || i == n)
res += fx[i];
else if (i % 2 != 0)
res += 4 * fx[i];
else
res += 2 * fx[i];
}
res = res * (h / 3);
return res;
}
• The calculation is based
Linear regression on the method of least
squares. The idea
behind it is to minimise
the sum of the vertical
distance between all of
the data points and the
line of best fit.
Interpolation
Practice problems:
• Find a real root of the equation -4x + cos x + 2 = 0, by Newton Raphson method
up to four decimal places, assuming x0 = 0.5
• Find a real root of the equation -4x + cos x + 2 = 0, by Bisection method up to
four decimal places.
• Using method of least squares find a linear relation between the weight of an
animal and its running speed based on the data in the table:
• If a gorilla weights 100 kg,
interpolate and find its maximum running speed.
Practice problems:
• With the help of the Trapezoidal & Simpson’s one third rule, the formula finds
the area under the curve y = x2 between x = 0 and x = 4.
• Solve the following using C++
Gauss Elimination method

You might also like