Question

Please write a VBA program for 1b and for 2. I am lost. Thank you.

Numerically integrate the below integral doubling the number of intervals until the relative true error falls below 0.01%. Wh

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOLUTION

program integration
! declaring the variable values
      real results,simp13_res,simp38_res,a,b,error
      real f
      integer n
      external f
         results=0.0
         n=0
         a=0.0
         b=1.0
         error=0.0
       write(*,*)achar(10),achar(10)
       write(*,*)"Intergration of (x^n*e^(x-1)) by dx range of 0 to 1"
10     write(*,*)achar(10)
       write(*,*)"Enter 0 to exit from the program"
       write(*,*)"Enter n : "
       read(*,'(i10)')n
!to exit      
       if(n==0)then
         goto 20
       end if
!factorial function calling
        results=factorial(n)   !calling the function factorial
        write(*,*)achar(10),"Recursion Solution = ",results   ! print the value of the function
!get simpson 1/3 solution
        call simpson13(f,a,b,simp13_res,real(n))
        write(*,*)achar(10),"Simpson 1/3 Solution= ",simp13_res
        error=(results-simp13_res)*100/results
        write(*,*)"Relative True Error in Simpson 1/3 (%) = ",abs(error)
       
        error=0.0
!get simpson 3/8 solution       
        call simpson38(f,a,b,simp38_res,real(n))
        write(*,*)achar(10),"Simpson 3/8 Solution = ",simp38_res
        error=(results-simp38_res)*100/results
        write(*,*)"Relative True Error in Simpson 3/8 (%) = ",abs(error)
!continue       
      goto 10
20    continue
      end program integration
! end of the main program, functions are below which is used in this program
!recursive algorithm
      recursive function factorial(n) result(results)
         real results,first,x
         integer n
            x=1
            first=1/exp(x)
            if(n<=0) then
              results = 0
              return
            else if(n==1) then
              results=1/exp(x)
              return
            else
              results=1-n*factorial(n-1)
              return
            end if
      end function factorial
!simpson 1/3 algorithm
      Subroutine simpson13(f,a,b,simp38_res,n)
         real a,b,x,n,h,f,simp38_res
         h=(b-a)/2.0
         simp38_res=h*(f(a,n)+f(a+h,n)+f(b,n))/3.0
         return
      end Subroutine simpson13
!simpson 3/8 algorithm
      Subroutine simpson38(f,a,b,simp13_res,n)
         real a,b,x,n,h,f,simp13_res
         h=(b-a)/3.0
         simp13_res=h*3.0*(f(a,n)+3.0*f(a+h,n)+3.0*f(a+2*h,n)+f(b,n))/8.0
         return
      end Subroutine simpson38
!function to integrate
      function f(x,n) result(res)
         real x,n,res
         res=(x**n)*exp(x-1)
         return
      end function f
Add a comment
Know the answer?
Add Answer to:
Numerically integrate the below integral doubling the number of intervals until the relative true...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 1: Numerically integrate function f(x) given on the right from x=0 to x=10. Use the...

    Question 1: Numerically integrate function f(x) given on the right from x=0 to x=10. Use the f(x)= x2 - 6x + 16 Trapezoidal Rule and the Simpson's 1/3 Rule and compare the results. Use at least 4 50 + 15x - ye? decimal digits in your calculations and reporting. Organize and report each one of your solutions in a calculation table and identify your result clearly. a) Divide the interval into 5 subdivisions. Calculate the integral first using the Trapezoidal...

  • 3. Evaluate the triple integral below (a) analytically, (b) using the composite trapezoidal rule ...

    3. Evaluate the triple integral below (a) analytically, (b) using the composite trapezoidal rule with n 2, (c) a single application of Simpson's 1/3 rule, and (d) for each approximation, determine the true percent relative error based on (a). 2yz)dx dy dz 3. Evaluate the triple integral below (a) analytically, (b) using the composite trapezoidal rule with n 2, (c) a single application of Simpson's 1/3 rule, and (d) for each approximation, determine the true percent relative error based on...

  • 2. The following integral 2 dr can be computed exactly (a) Estimate the integral using the...

    2. The following integral 2 dr can be computed exactly (a) Estimate the integral using the composite trapezoidal rule with n = exact value of integral and compute the true percent relative error for this approximation 4. Calculate the (b) How many subintervals would be needed to estimate the integral with the composite trapezoidal rule with an accuracy of 102? (c) Estimate the integral using the composite Simpson's 1/3 rule with n = true percent relative error for this approximation...

  • 1. Use the Trapezoidal Rule to numerically integrate the following polynomial from a = 0.5 to...

    1. Use the Trapezoidal Rule to numerically integrate the following polynomial from a = 0.5 to b = 1.5 f(x) = 0.2 + 25x – 200x2 +675x3 – 900x4 + 400x5 Use three different number of segments and show that higher number of segments give lesser relative error considering the exact value of the integral, which is 49.3667. 2. Write a MATLAB or OCTAVE code to solve the above problem numerically and verify your result. Copy/paste the code and answers...

  • 3. Evaluate the following double integral (a) analytically. (b) using multiple-application of the...

    3. Evaluate the following double integral (a) analytically. (b) using multiple-application of the trapezoidal rule with n 2 and compute the true relative error. (c) using single application of Simpson's 1/3 rule and compute the true relative erro. 3. Evaluate the following double integral (a) analytically. (b) using multiple-application of the trapezoidal rule with n 2 and compute the true relative error. (c) using single application of Simpson's 1/3 rule and compute the true relative erro.

  • 2. Use the Trapezoidal Rule to numerically integrate the following polynomial from a tob 1.5 f(x)...

    2. Use the Trapezoidal Rule to numerically integrate the following polynomial from a tob 1.5 f(x) = 0.2 + 25x-200x' + 675xs_ 900x. + 400x5 Use three different numbers of segments (n- 2, n 3, and n 4) and show the effect of the number of segments on relative error considering the exact value of the integral which is 48.7719. (Note: Show the steps of calculation).

  • 2- Evaluate the following integral: 0.4 | Vcos(2x)dx a) By calculator, b) Composite trapezoidal rule (with...

    2- Evaluate the following integral: 0.4 | Vcos(2x)dx a) By calculator, b) Composite trapezoidal rule (with segment no. n=4) and determine the true relative error, c) Composite Simpson's 1/3 with n =4 and determine the true relative error, d) Simpson's 3/8 rule determine the true relative error, e) Composite Simpson's rule, with n =5, determine the true relative error.

  • Numerical Methods Consider the integral 2 (a) [16 marks] Use the composite Simpson's rule with four intervals to calculate (by hand) approximate value of the integral Calculate the maximum value o...

    Numerical Methods Consider the integral 2 (a) [16 marks] Use the composite Simpson's rule with four intervals to calculate (by hand) approximate value of the integral Calculate the maximum value of the error in your approximation, and compare it with the true error. (b) 19 marks] Determine the number of subintervals n and the step size h so that the composite Simpson's rule for n subintervals can be used to compute the given integral with an accuracy of 5 ×...

  • Use Matlab code Consider the following function sin(x) Using the following parameters in your functions: -func:...

    Use Matlab code Consider the following function sin(x) Using the following parameters in your functions: -func: the function/equation that you are required to integrate -a, b: the integration limits n: the number of points to be used for the integration I:Integral estimate a) Write a function capable of performing numerical integration of h(x) using the composite trapezoidal rule. Use your function to integration the equation with 9 points. Write a function capable of performing numerical integration of h(x) using the...

  • Objective The usual procedure for evaluating a definite integral is to find the antiderivative of the...

    Objective The usual procedure for evaluating a definite integral is to find the antiderivative of the integrand and apply the Fundamental Theorem of Calculus. However, if an antiderivative of the integrand cannot be found, then we must settle for a numerical approximation of the integral. The objective of this project is to illustrate the Trapezoidal Rule and Simpson's Rule. Description To get started, read the section 8.6 in the text. In this project we will illustrate and compare Riemann sum,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT