Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

By Trapezoidal rule and simpsons rule. approximation and error. The sample program below uses the lem-endpoint rule, the right-endpoint rule and the trapezoid rule to

By Trapezoidal rule and simpsons rule. approximation and error.

image text in transcribedimage text in transcribed

The sample program below uses the lem-endpoint rule, the right-endpoint rule and the trapezoid rule to approximate the definite integral of the function. Matlab comments flow the percent sign (%) % Left endpoint of integral o- pi; N 13; h-(b-a)/N % Right endpoint % The number of sub-intervals (INI must be even for % Creates a vector of N+1 evenly spaced points between lal and Ibl f-sin(x); % The function to integrate !exact -2; % The exact integral Itrapezoid-e Isimpson-B for k-1:N %Note that the vector f has (N+1) elements end; for k-1:(N/2) Itrepezoid-Itrapezoid+h (f (k)-f(k-1))/2; end Exact integral - f.In', Iexact) fprintf( forintt(' forintf Trapezoldal %f,'n',1trapezold); %in.,1simpson); approxination- Simpson approximation : fprintf( n forintt(' Trapezoldal error-%f.Vn.absttradezold-Iexact)); fprintf % Output from this program Simpson error %f. ",abs( Isin son-lexact)); Exact integral-2.80038 Trapezoidal approxinatian1.983524. Simpson approximation - 2.830110 Trapezoidal error e.16476 Simpson error -000110 New Matlab ideas AFor Loop. Repeat the code between Tor and 'end' once for each number between 1 and N the fprintf statement. This is a formatted printing statement, which uses almost identical syntax to the C programming language. It is used here to format the output for display. You should be able to use this part of the program without modifying it Parameters used in this program a,b: the limits of integration x: the variable of integration f:the integrand N: the number of sub-intervals h: the width of each sub-interval IT: the trapezoidal appro ormation IS: the Simpson approimation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

3. What values would you say are your core values?

Answered: 1 week ago