Professional Documents
Culture Documents
CE 007 (Numerical Solutions To CE Problems)
CE 007 (Numerical Solutions To CE Problems)
Submitted by:
Santos, Michelle Anne F.
1820027
I swear on my honor that I did not use any inappropriate aid, nor give such to others, in accomplishing
this coursework. I understand that cheating and/or plagiarism is a major offense, as stated in TIP
Memorandum No. P-04, s. 2017-2018, and that I will be sanctioned appropriately once I have committed
such acts.
b. Newton's Method
1. Start the program.
2. Initialize x and xo
3. For k = 0,1,2, . . . do
4. if f(xk) is sufficiently small then
5. Calculate x* = xk
6. Display value of x*
7. Calculate xi = xi-1 - f(xi-1)/f '(xi-1)
8. if |xk+1 − xk| is sufficiently small then
9. x* = xk+1
10. Display value of x*
11. Stop the program.
c. Neville's Method
1. Start the program.
2. Order interpolation points in x.
3. Set Pi = yi
4. Determine C1,i, D1,i (linear interpolation)
5. Check convergence.
6. If not adequate construct P01
7. Construct Cm,i, Dm,i
8. Check for convergence, if too large.
9. Construct P01...m; loop to 6
10. If OK, Stop and get error estimate.
f. Polynomial Fit
1. Start the program.
2. Input order of polynomial to be fit, m.
3. Input number of data points, n.
4. If n < m+1, print out an error message that regression is impossible and terminate the process.
If n is greater than or equal to m+1, continue.
5. Compute the elements of the normal equation in the form of augmented matrix.
6. Solve the augmented matrix for the coefficients ao, a1, a2, . . an, using an elimination method.
7. Print out the coefficients.
8. Stop the program.
g. Exponential Fit
1. Obtain an approximation of b
2. Using b, obtain an approximation of a
3. Using a,b, obtain an approximation of c
4. Discard a,b and replace y = ae^(bx) + c ....by.... y - c = ae^(bx)
5. ln(y - c) = ln(a) + bx ...........a linear function
6. Call the least square method to find a,b of the best fitting line
h. Bisection Method
1. Start the program.
2. Define function f(x)
3. Choose initial guesses x0 and x1 such that f(x0)f(x1) < 0
4. Choose pre-specified tolerable error e.
5. Calculate new approximated root as x2 = (x0 + x1)/2
6. Calculate f(x0)f(x2)
• if f(x0)f(x2) < 0 then x0 = x0 and x1 = x2
• if f(x0)f(x2) > 0 then x0 = x2 and x1 = x1
• if f(x0)f(x2) = 0 then goto (8)
7. if |f(x2)| > e then goto (5) otherwise goto (8)
8. Display x2 as root.
9. Stop the program.
j. Secant Method
1. Find points x0 and x1 such that x0<x1 and f(x0)⋅f(x1)<0.
2. Find next value using
• Formula-1 : x2=x0-f(x0)⋅(x1-x0 / f(x1)-f(x0))
• Formula-2 : x2= (x0⋅f(x1)-x1⋅f(x0)) / (f(x1)-f(x0))
• Formula-3 : x2=x1-f(x1)⋅(x1-x0) / (f(x1)-f(x0))
• (Using any of the formula, you will get same x2 value)
3. If f(x2)=0 then x2 is an exact root,
• Else x0=x1 and x1=x2
4. Repeat steps 2 & 3 until f(xi)=0 or |f(xi)|≤Accuracy
k. Newton-Raphson Method
1. Start the program.
2. Read x, e, n, d
• *x is the initial guess
• e is the absolute error i.e the desired degree of accuracy
• n is for operating loop
• d is for checking slope*
3. Do for i =1 to n in step of 2
4. f = f(x)
5. f1 = f'(x)
6. If ( [f1] < d), then display too small slope and goto 11.
• *[ ] is used as modulus sign*
7. x1 = x – f/f1
8. If ( [(x1 – x)/x1] < e ), the display the root as x1 and goto 11.
• *[ ] is used as modulus sign*
9. x = x1 and end loop
10. Display method does not converge due to oscillation.
11. Stop the program.
B. Solve the following problems (you can use hand calculation).
1. Use Lagrange interpolation and Newton interpolation methods to find a cubic polynomial that
interpolates the following data points: {(−2, −3), (−1, 1), (0, −1), (1, −3)}. After applying each
of these methods, convert the polynomial to the standard form P3(x) = a0 + a1x + a2x2 + a3x3
(if it is not already in this form).
2. Given the set of data points {(−3, −1), (−2, 1), (0, 2), (1, 3), (3, 2)}, fit a straight line y = mx + b
that approximates the points in the least-squares sense.
(a) Write a least-squares system Ax ≈ b which can be used to obtain values for m and b.
(b) Solve the obtained system above using the method of normal equations.
Machine Problem:
1. Use Newton’s method to
(a) Create a program that computes for the power am/n given a real number a. You are not allowed to use
roots or raise numbers to fractional powers in the formula. [Hint: This value is the solution of xn − am = 0.]
#include <iostream>
using namespace std;
int main()
{
int exponent;
float base, result = 1;
cout << base << "^" << exponent << " = ";
while (exponent != 0) {
result *= base;
--exponent;
}
return 0;
}
(b) Create a program that computes for arcsin(x) of a given number x ∈ [0, 1]. You are not allowed to use
inverse trigonometric functions in the formula but trigonometric functions such as sin, cos, tan are
allowed.
// CPP code to illustrate
// the use of asin function
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265
int main()
{
double x, ret, val;
return 0;
}
References:
Anonymous, (April 20, 2014). Newton Raphson Method Algorithm and Flowchart. Retrieved from:
https://www.codewithc.com/newton-raphson-method-algorithm-flowchart/
Anonymous, (2021). Retrieved from:
https://atozmath.com/example/CONM/Bisection.aspx?he=e&q=se
Anonymous, (2021). Lagrange Interpolation Method Algorithm (Step Wise). Retrieved from:
https://www.codesansar.com/numerical-methods/lagrange-interpolation-method-algorithm.htm
Anonymous. Exponential Curve Fitting. Retrieved from:
http://www.davdata.nl/math/expfitting.html
Gupta, Akash. (October 30, 2020). asin() and atan() functions in C/C++ with Example. Retrieved
from: https://www.geeksforgeeks.org/asin-atan-functions-cc-example/
Weisstein, Eric W. (April 2021). Normal Equation. From MathWorld--A Wolfram Web
Resource. https://mathworld.wolfram.com/NormalEquation.html