Write C program to compute the integral

Assignment Help C/C++ Programming
Reference no: EM132662755

Numerical Integration

Question 1. Write C program to compute the integral I = ab f (x)dx where

f (x) = a0 + a1x + a2x2 + a3x3 + a4x4 + a5x5

and
a0 = 0.84885406
a1 = 31.51924706
a2 = -137.66731262
a3 = 240.55831238
a4 = -171.45245361
a5 = 41.95066071

with a = 0.0 and b = 1.5 using all the following approaches

(a) exact integration (when the integrand is a polynomial function, the integral can be exact).
(b) trapezoidal rule with the number of sub-intervals ni = {1, 2, 3, ...., 12}
(c) Simpson's one-third rule with the number of sub-intervals ni = {2, 4, 6, 8, 10, 12}
(d) Simpson's three-eights rule with the number of sub-intervals ni = {3, 6, 9, 12}

Please tabulate your results for (b), (c) and (d) and compare your results with the exact solution you obtained in (a). Show the order of accuracy of the methods used in (b), (c) and (d) by computing

order = log(∈i/∈i-1)/log(ni-1/ni)               i = 0, 1, ....

where ∈i is the absolute error between the numerical integration and the exact solution. ni is the number of intervals. Note the above formula becomes calculable only when i ≥ 1.

(e) Gauss quadrature rule with the number of Gauss points ni = {1, 2, 3, 4}

R-K Time Integration

Question 2. Write a C program to solve

dy/dt = -y

using the Runge-Kutta method. Note that the analytical solution of this equation is y = e-t which can be used to compare with your numerical solution. To start the time integration, t0 = 0, y0 = 1.0 are given. Use your program to find the solution at tn = 6.0.

(a) RK-1.
(b) RK-2 (version 2).
(c) RK-3.
(d) RK-4 (version 1).

Requirements: for each method, please use the time step hi= {0.1, 0.05, 0.025, 0.0125, 0.00625} and compare your solution with the analytical solution. Calculate the order of accuracy of each method using the following formula and show it in the table.

order = log(∈i/∈i-1)/log(hi/hi-1)

where ∈ is the absolute error between numerical integration and the analytical solution.

h is the time step. Please tabulate your results as follows:

hi

RK-1

RK-2

RK-3

RK-4

|i|

order

|i|

order

|i|

order

|i|

order

0.1

 

-

 

-

 

-

 

-

0.05

 

 

 

 

 

 

 

 

0.025

 

 

 

 

 

 

 

 

0.0125

 

 

 

 

 

 

 

 

0.00625

 

 

 

 

 

 

 

 

Finite Difference Method

Question 3. Use the finite difference method to solve the following advection (wave equation) problem:

∂u/∂t + ∂u/∂x = 0, 0 ≤ x ≤ 1

u(x, 0) = 1, 0.25 ≤ x ≤ 0.75   , periodic b.c.
u(x, 0) = 0, otherwise  , periodic b.c.

which is about a square wave propagated to the right at a constant speed of unity.

(a) Periodic b.c. means when the wave exits the right boundary it enters the left boundary.

(b) Note that this is an initial-value problem. You can use the explicit forward-time- backward-space (FTBS) scheme with appropriate time step determined by the stability condition

Δt ≤ Δx/a
where a is the wave speed (= 1 in this problem) and Δx = 1/40.

(c) plot u(x) vs. x at three time instants t = 0.0, t = 0.5, t = 1.0. Exact solution must also be plotted in the same figures for comparison purposes. Solid line is used for the exact solution and symbols for the numerical solution.

Question 4. Solve the following heat equation at t = 3.0.

∂T/∂t = α. ∂2T/∂x2 on 0 ≤ x ≤ L

T (x, 0) = 6 sin (πx/L), T (0, t) = 0, T (L, t) = 0

where α = 0.2 and L = π.

(a) The exact solution for this problem is given

T (x, t) = 6 sin (πx/L) e-α(π/L)2t

which can be used to compare with your numerical solution.

(b) Use a mesh with Δx = L/40.

(c) Use the explicit forward-time-central-space scheme to solve the equation. The following formulation is used to determine the stable time step.

Δt ≤ (Δx)2/2α

Plot T vs. x at t = 3.0. Solid line is used for the exact solution and symbols for the numerical solution.

(d) Use the implicit Crank-Nicholson scheme to solve the same problem. The time step can take 5 times the Δt in the previous explicit scheme (b). The Thomas algorithm (Google it online) can be used to solve the resulting tridiagonal system. Plot T vs. x at t = 3.0. Solid line is used for the exact solution and symbols for the numerical solution.

Reference no: EM132662755

Questions Cloud

What amount should be recognized as impairment loss : Listless Company acquired equipment on January 1, 2019 for P5,000,000. What amount should be recognized as impairment loss for 2020
Journalize the entries to record first semiannual interest : Journalize the entries to record the First semiannual interest payment. The bond discount is combined with the semiannual interest payment.
Describe the metabolic pathway : Briefly describe the metabolic pathway that your cells will use to generate ATP for the first 90 seconds of your mile.
How do you initially approach elmer : How do you initially approach Elmer? What is your demeanor? What do you ask Elmer that you likely do not know from the file material?
Write C program to compute the integral : Write C program to compute the integral - Calculate the order of accuracy of each method using the following formula and show it in the table
Calculate the labor rate variance for the month : Calculate the labor rate variance for the month. Comment on your answer.Standard direct labor-hours 4.8 hours per unit of MH70
Why is fermentation less effective than respiration : Why is fermentation less effective than respiration?
What amount should be recognized as impairment loss : The entity sold the machine for P650,000 on January 5,2020. What amount should be recognized as impairment loss in 2019
How does your chosen painting make use of color and line : How does your chosen painting make use of color and line? How does your chosen painting make use of symmetry or asymmetry? What is the effect of this technique?

Reviews

len2662755

10/13/2020 4:44:11 AM

READ THE QUESTION IN DETAIL AND USE THE FORMULA OR METHOD DEFINED IN THE QUESTION. Please find the attached. Use C Language. I need Code and Result in Word Document for each question. This is a Ph.D. level work and every question should be programmed according to the question and not just using random code to get the output. Make sure you satisfy the requirements in each question. For example, if a question should be solved using a certain theory or method then the formula should also be from that theory. Please use the formulas as given/instructed in the questions. PLEASE GIVE ME ACCURATE SOLUTION TO EACH QUESTION.

Write a Review

C/C++ Programming Questions & Answers

  Check the program and correct it

Modify the attached program to not just say you won, lost, or tied but to say how, no matter if you win, lose, or tie.

  List at least one specific example of when a void function

List at least one specific example of when a void function would be appropriate and one specific example of when a non-void function would be appropriate.

  Write a program in c to implement bubble sort

Write a program in c to implement bubble sort?

  Create a friend class bestfriend to the class frac

Create a friend class BestFriend to the class frac. Inside the class BestFriend, and implement a function outputfrac() to print the content of the frac instance

  Program that asks the user to enter a number from 1 to 50

Print the statement "Programming is fun" the number of times entered by the user using a for loop.

  Define the method computediscount

It should define the method computeDiscount so that if the quantity purchased of an item is more than minimum, the dis-count is percent percent.

  What would a more correct functional data structure

How does the type cast of cname cause Data-Type-Mismatch and what would a more correct Functional Data Structure Type have been

  Consider implementing subnetting to support three department

Consider implementing subnetting to support three departments within an organization. The three departments P, Q and R need support for 30, 40 and 60 hosts.

  Select the total number of shippers for orders

Select the total number of Shippers for Orders (Hint: use COUNT(ShipVia) as TotalProducts to return non-null counts.

  Prepare a program for a bank that allows the user

Prepare a program for a bank that allows the user to enter an amount of money in cents. Show the number of whole dollars the bank will give the customer in exchange.

  Textual table describing the catalogues of retail stores

Write a function to read a series of catalogue records from a file into a vector of catalogue objects. You will need to use the class ifstream, which is derived from istream, like so:

  Implement stack-based bidirectional

Describe and explain in detail the concept forward and bidirectional iterators on Set and Map container classes and implement Stack-based bidirectional "in-order", "pre-order", and "post-order" iterators for binary trees

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd