Question

For the integral below, write a program to do the trapezoid rule using the sequence of...

For the integral below, write a program to do the trapezoid rule using the sequence of mesh sizes h = (b – a)/2, (b – a)/4, (b – a)/8, ..., (b – a)/128, where b – a is the length of the given interval: f(x) = e−x sin(4x), [0, pi], I(f) = (4/17)(1 − e^-pi) = 0.2251261368. Verify that the expected rate of error decrease is obtained. Attach your code and a plot of error vs. h.

Homework Answers

Answer #1

Please use comments section for queries:

We write the C-Program using Function. We define a function where .

The code is as follows:

#include<stdio.h>

#include<math.h>

main()

{

int n,i;

float a,b,h,x,sum=0,int;

printf("Enter the number of subintervals");

scanf("%d",&n);

printf("Enter the lower limit of the integral");

scanf("%f",&a);

printf("Enter the upper limit of the integral");

scanf("%f",&b);

h=fabs(a-b)/n;

for(i=1,i<n;i++)

x=a+i*h;

sum+=f(x);

}

int=(0.5)*h*(f(a)+f(b)+2*sum);

printf("the integral is %f",int);

}

float f(float x)

{

return exp(-x)*sin(4*x);

}

Plot of error vs h:

Considering

we get the following graph:

Know the answer?
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
Similar Questions
Problem 1....... you can use Matlab The following Scilab code generates a 10-second “chirp” with discrete...
Problem 1....... you can use Matlab The following Scilab code generates a 10-second “chirp” with discrete frequencies ranging from 0 to 0.2 with a sampling frequency of 8 kHz. clear; Fs = 8000; Nbits = 16; tMax = 10; N = Fs*tMax+1; f = linspace(0.0,0.2,N); x = zeros(f); phi = 0; for n=0:N-1 x(n+1) = 0.8*sin(phi); phi = phi+2*%pi*f(n+1); end sound(x,Fs,Nbits); sleep(10000); //allows full sound to play Add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the...
Problem 3 you can use Matlab and also i give u the Problem 1 code its...
Problem 3 you can use Matlab and also i give u the Problem 1 code its on Matlab Using the same initial code fragment as in Problem 1, add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the impulse response of an IIR bandpass filter with band edge frequencies 750 Hz and 850 Hz and based on a 4th order Butterworth prototype. Name your program p3.sce this is the Problem 1 code and the solutin clear; clc;...
Problem 1 ...... you can use Matlan i got one so all what i need is...
Problem 1 ...... you can use Matlan i got one so all what i need is 2, 3 and 4 one of them or all of them .. thanks The following Scilab code generates a 10-second “chirp” with discrete frequencies ranging from 0 to 0.2 with a sampling frequency of 8 kHz. clear; Fs = 8000; Nbits = 16; tMax = 10; N = Fs*tMax+1; f = linspace(0.0,0.2,N); x = zeros(f); phi = 0; for n=0:N-1 x(n+1) = 0.8*sin(phi); phi...
a)Program a calculator or computer to use Euler's method to compute y(1), where y(x) is the...
a)Program a calculator or computer to use Euler's method to compute y(1), where y(x) is the solution of the given initial-value problem. (Give all answers to four decimal places.) dy dx + 3x2y = 9x2, y(0) = 4 h = 1     y(1) = h = 0.1     y(1) = h = 0.01     y(1) = h = 0.001     y(1) = (b) Verify that y = 3 + e−x3 is the exact solution of the differential equation. y = 3 + e−x3      ⇒     y'...
1) Derive the quotient rule ( f g ) ′ = (f ′ ⋅ g −...
1) Derive the quotient rule ( f g ) ′ = (f ′ ⋅ g − f ⋅ g ′ )/g 2 using the product rule and the chain rule. I was able to get this with product rule(i think) but unsure how to use chain rule 2) Identify a rate of accumulation (or decay) in your life that changes over time. Be creative. a) Describe it in a sentence or two: the rate of accumulation of pages read this...
The data below were obtained to predict the sound frequency to which a person’s ear will...
The data below were obtained to predict the sound frequency to which a person’s ear will respond based upon the length of time a person has been exposed to a high level of noise. Here “length of exposure” is the amount of time in weeks that a person has been living close to a major airport and the “hearing range” is reported in thousand cycles per second. Length of exposure In weeks (Left) Hearing range In thousand cycles per second...
Below are three different codes in Matlab, please copy those your matlab and answer the following...
Below are three different codes in Matlab, please copy those your matlab and answer the following questions: Thank you for your help!!!! 1.1 Baseband Signal a) Plot time versus baseband signal (m_sig). b) Plot freq versus baseband signal spectrum (M_fre). 1.2 Amplitude Modulation – Suppressed Carrier. a) Plot time versus the DSB-SC signal (s_dsb). b) Plot freq versus the DSB-SC signal spectrum (S_dsb). 1.3 Coherent Demodulation a) Plot freq versus the pre-filtered signal (S_dem). b) Plot freq versus the post-filtered...
Write a program of wordSearch puzzle that use the following text file as an input. The...
Write a program of wordSearch puzzle that use the following text file as an input. The output should be like this: PIXEL found (left) at (0,9). ( Use JAVA Array ) .Please do not use arrylist and the likes! Hints • The puzzle can be represented as a right-sized two-dimensional array of characters (char). • A String can be converted into a right-sized array of characters via the String method toCharArray. . A word can occur in any of 8...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads data from a file and performs regression analysis using polyfit and polyval. The function shall have the following features: The input arguments shall include the file name (string), a vector of integers for the degrees of polynomial fits to be determined, and an optional plot type specifier (‘m’ for multiple plots, ‘s’ for a single plot - default). The data files will be text...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT