CS117 – ComputerProblemScienceSet #11704 – S (Solution)

$ 25.00
Category:

Description

Nathaniel Aquino nbaquino2@up.edu.ph
Elaine T. Pajarillo etpajarillo@up.edu.ph
Junius Wilhelm G. Bueno
Gov. Pack Road, Baguio City, Baguio 2600
November 16, 2023
1. Suppose you want the interpolating polynomial P3(x) about the points (0, 0),(0.5, y), (1, 3), and (2, 2) to have a leading coefficient of 1. Find the value of y.
Solution: Given the points, we have,

where . Hence we have,
0() = ((0(−−11))((0−)−22))((−0−3)3) , 1() = ((1−−00))((1−−22))((−1−3)3) ,.
1 3
Plugging in the given −1)(we2−now3) have, 3 (3−0)(3−1)(3−2)

83
1() = (0.(5−−00))((0.5−−11))((0−.52−) 2) = −338 +2 = 3 − 82 + 163

Now,3()plugging(2−0)(2in−0.the5)(2−given1) 3 values and3 the− computed2 + 6 we now have,
() ()
3() = 0()(0) + 1()(1) + 2()(2) + 3()(3) = 0() * 0 + 1() * + 2() * 3 + 3() * 2
Since
2.Therefore,Write a 3functionwe haveiny polyinterp.py= 198 or y = 2.375.that implements the Newton form of Lagrange
Polynomial. Use this to plot the interpolating polynomial pn of degree n = 5, 10, 20
ofincludingthe functionthe endpoints).() = (,Use1−20. 2 +threeInclude4)2 ondifferentthetheapproximateintervalCartesian[−2,planesfunction2] (usetoequidistantnormcomparef − thepnodesplot
offorf(x)n =and5, 10pn, 20for, eachn = 5with, 10 9,000 nodes. || ||−2,2,∞

To answer the problem, we first wrote a code that implements the Newton Form of the Lagrange Polynomial. This function takes the parameters f and x, as the function to be interpolated and the x-coordinated of the points to be used for the interpolation and returns the p for the interpolating polynomial function. This function initializes by computing the divided differences based on the input data and creates a smooth curve passing through the data points to interpolate values in given data points.
Implementation:

This code performs the polynomial interpolation using the Newton-Lagrange method and displays the results for different node counts. The target function, f(x), is defined from the given problem, and the NewtonLagrangeInterpolation function is imported to generate interpolating polynomials. Plots show the target function and interpolating polynomials for n= 5, 10, 20, making it easier to assess interpolation accuracy. The norms of differences between the target function and interpolating polynomials are computed and outputted, and equidistant nodes are constructed.
Results:

Approximate function norm for n = 5, 10, 20

Plot of the Interpolating Polynomial p_n of degree n = 5, 10, 20
Using the code, we computed the approximate function norm between the function and interpolating polynomial to measure the accuracy. We also outputted the plot of the function and the interpolating polynomial to provide visuals for the approximation.
3. With the same function in item number 2, minimize the supremum norm by considering three subintervals of [-2,2] and using appropriate Lagrange interpolating polynomials with degree of at most 10 at each subinterval. In your computation for function norm, use 3000 nodes on each of the considered intervals and take the maximum of the norms. Also, include the plot of the piecewise interpolating polynomial.
Implementing the same code from the polyinterp.py with the Newton Form of the Lagrange Polynomial, the supremum norm is calculated by determining the maximum absolute difference between the original function and the corresponding interpolating polynomial within each subinterval. We first iterated through the subintervals, identifying the one with the maximum function norm. It then displayed the piecewise interpolating polynomial for the interval with the maximum norm, including the interpolation points. The results, including maximum norm values and associated subintervals, are printed as well as the plots for visualization into the accuracy of the piecewise interpolation, highlighting the subinterval where the supremum norm is maximized.
Code:

Output:

The result shows the maximum function norm values for three subintervals [−2,−1],[−1,1], and [1,2]. The supremum norm measures the maximum absolute difference between the original function and the Lagrange interpolating polynomial within each subinterval. The norm values for [−2,−1] and [1,2] are 0.00021575, indicating highly accurate interpolation, while [−1,1] has a slightly larger norm of 0.00716158 which can indicate a more substantial difference. With this, we can conclude that the maximum function norm occurs in [−1,1] with 0.00716158.
(4)(
function.4.Solution:Show usingUseGiventhisNewton’stheto approximatepoints,finitewe differencehave(4)(1) bythatthe given0) candatabepoints.approximated by the
0 = 0, 1 = 0. 025, 2 = 0. 05, 3 = 0. 1 4 = 0. 125, 5 = 0. 15, 6 = 0. 175, 7 = 0. 2
(0) = 0. 01, (1) = 0.,03, (2) = 0. 005, (3) = 0. 04, (4) = 0. 02, (5) = 0. 01, (6) = 0. 03 (7) = 0. 02
The Newton’s finite difference, is given by
h = 0.05 and
4(0. 1) ≈ (0.1+ 2(0.05)) − 4(0.1 + 0.05) + 6(0(.050.1))4 − 4(0.1 − 0.05) + (0.1 − 2(0.05))

4(0. 1) ≈ (0.2) − 4(0.15) + 6(0.14) − 4( 0.05) + (0)
((00..0504))

4444((((0000…. 1111)))) ≈≈≈≈ 33600(000..0200000625.020 −.)21 −0 . 044(00.+00000625.01 0.)24 + −6(0 0.05.02) 4+ − 0 4.01( 0 .005) + 0.01
Therefore, we can conclude that the 4th derivative of the function with x=1 and h=0.05, is approximated to be 33600.
5. Approximate these integrals by Composite Simpson 1/3 (Simpson Thirds) and 3/8 (Simpsoneights) rules. Divide the interval of integration into 3,000 equal parts.
To approximate theseA. integrals we2need to considerB. ∫21 the composite Simpsons ⅓
and Simpsons ⅜ rules. These two are numerical integration methods based on Simpson’s rule. Simpson’s rule is a numerical technique for approximating the definite integral of a function. It uses quadratic approximations for small intervals of the function and is known for its simplicity and accuracy for smooth functions.
For quadrature.py

This works by dividing the interval [a, b] into smaller subintervals and picking specific points within each. Furthermore, It calculates a weighted sum of function values at these points, using a pattern of 1-4-2-4-…-2-4-1. This sum is scaled by the width of the subintervals (h) and divided by 3. Mathematically, the process can be represented as:

The weighted sum estimates the area under the curve. The algorithm’s simplicity lies in its systematic approach to approximating the integral by combining quadratic approximations within each subinterval.

In simple terms, it divides the integration interval [a, b] into smaller subintervals, each of width h. The algorithm systematically calculates the function values at various points within these subintervals, accumulating sums with specific weights. Notably, it places emphasis on every third function value. Mathematically, the result is given by

This approach simplifies the understanding of Simpson’s 3/8 rule, illustrating how the algorithm strategically combines function values to provide an approximation of the integral.
Implementation:
The first function, f_1(x) = sqrt(1 + cos(x)^2), involves the square root of the sum of 1 and the square of the cosine of x. The second function, f_2(x) = sin(x)/x, represents the ratio of the sine of x to x. Both functions are then integrated over specified intervals using two different numerical integration methods: Simpson’s 1/3 rule and Simpson’s 3/8 rule. The integration is performed on two different intervals: [0, π] for f_1(x) and [1, 2] for f_2(x). A total of 3000 subintervals (n = 3000) are used for both integrations, providing a reasonably accurate approximation.
Code:

The results of the numerical integrations using Simpson’s 1/3 rule and Simpson’s 3/8 rule are displayed for two different functions over their specified intervals.

The close result between the results indicates that both methods are highly accurate for integrating the function f_1(x) = sqrt(1 + cos(x)^2) over the interval [0, π]. But notice that the approximation using Simpsons’s ⅜ is quite accurate than Simpson’s ⅓ that is because Simpson’s 3/8 rule uses cubic approximations (third-degree polynomials) rather than Simpson’s 1/3 who rule uses quadratic approximations (second-degree polynomials).

Similarly, for letter b, both methods can be accurate for smooth functions, but the choice between them depends on the specific needs and characteristics of the integration problem at hand.
6. Solve the initial value problem = − 1 2 , y(1) = 1, to find y(1.2) by
Runge-Kutta method of order four (RK4) and Runge-Kutta-Heun method of order three (RKH3) with step size 0.001.
We are solving a math problem: finding,
starting at . The goal is to discover
RK4 and RKH3, with a step size of 0.001. The solution is organized neatly in
ODEscalar.py, containing the RK4 and RKH3 tools, and the final answer is in
Item6Imp.py. This methodical approach efficiently tackles the initial value problem using numerical methods.
ODEscalar.py

Based on the course notes, the definition and formula for RK4 is given by:

The algorithm iteratively approximates the solution by evaluating four weighted increments (k1, k2, k3, k4) at different points within each step. These increments are determined by the function f(t, y) representing the ODE and are combined using a weighted average to update the current value of y.

The algorithm divides the problem into small steps, each calculated based on the current state of the system. For each step, it estimates the rate of change at the current point (k1) , as well as at two intermediate points within the step (k2 and k3). Based on the course note, the formula for rk3,

Implementation:

Result:

The small difference between the two results can be attributed to the inherent differences in the numerical methods. RK4 is known for its higher accuracy compared to RKH3, as it involves more stages and higher-order approximations. The results indicate that both RKH3 and RK4 provide reasonably close approximations for y(1.2), with RK4 offering a slightly more accurate result. Because it is higher-order method. The “order” of a numerical method indicates the rate at which the method’s error decreases with smaller step sizes. Higher-order methods generally provide more accurate results for the same step size compared to lower-order methods.

Reviews

There are no reviews yet.

Be the first to review “CS117 – ComputerProblemScienceSet #11704 – S (Solution)”

Your email address will not be published. Required fields are marked *