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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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