Question

MATLAB Create a function that provides a definite integration using Simpson's Rule Problem Summar This example demonstrates using instructor-provided and randomized inputs to assess a function problem. CustomSolution Details Solution 2: O of 4 tests passed Test Results Submitted less than a minute ago | ID: 13625953 | Size: 118 1fuAssessment: 0 of 4 Tests Passed Does the function pass the first test case? Error: You may not use the command(s) feval in yo

Problem Summar This example demonstrates using instructor-provided and randomized inputs to assess a function problem. Custom numerical tolerances are used to assess the output. Simpson's Rule approximates the definite integral of a function f(x) on the interval a,a according to the following formula + f (ati) This approximation is in general more accurate than the trapezoidal rule, which itself is more accurate than the leftright-hand rules. The increased accuracy of Simpson's rule is due to the fact that, while the trapezoidal rule approximates f as a linear function over an interval, Simpson's rule approximates f as a quadratic function, which leads to better results for smooth, nonlinear functions. In fact, it produces exact integral values for polynomials up to degree 3 By using Simpson's Rule over a sequence of n small, equally spaced subintervals and summing the results, we can approximate the definite integral of a function f over a larger interval [a, b] according to the formula: a + ai+ 2a) ai+1 ai where Δ= (which is constant with equal subinterval spacing) Your task is to complete the function I z simpson (f, a,b,n), which uses Simpson's method to approximate the definite integral value I of the input function f over the interval [a, b] using n subintervals. 1. Use the linspace function to create a vector x of n+1 equally spaced points 2. Define the value of Delta according to the formula above. You can use any two adjacent elements of x 3. Define the variable dI comesponding to value for the ith subinterval in the summand above 4. Set the range of values for the loop index i. These values will depend on your formula for dI When you have completed these tasks, call simpson using the test inputs provided and compare your results to the values given below. The absolute errors for both simpson and the trapezoidal method will be displayed for comparison. The first test uses a cubic function, for which Simpsons's method should returnthe exact value of 0.75 with no error . In the second test, your function should retum a value close to the true value of 1, with smaller eror than the trapezoidal method. Once your function returns reasonable values for the given test inputs, submit it for assessment.
Solution Details Solution 2: O of 4 tests passed Test Results Submitted less than a minute ago | ID: 13625953 | Size: 118 1function I-simpson (f,a,b,n) 2 %takes in parame 3 %interval b for integration and number of intervals as n 4 x linspace (a,b,n+1); Delta (b-a)/nstep of integration 6 fa-f(a);%value of function at a 7 fb-f(b);%value of function at b 1-0;%initialize ff to θ ter as function handel f, starting interval a and ending 1 I-I/3; 11 for i-2:2:nistraversing on even numbers i 12 dI-feval(f,x(i))/3;%value of function at x 14 end is for i=3: 2:nXtraversing on odd numbers i 16 dI-feval(f,x(i))/3;value of function at x 18 end 19 1 (Delta)"(1);%finally add first and last points tto all the sum and divide by 3 20 end 21
Assessment: 0 of 4 Tests Passed Does the function pass the first test case? Error: You may not use the command(s) feval in your code Your function must return the exact value of 0.75 for the Test 1 input values provided Check your formulas for Delta and dI and make sure your loop iterates over the correct range of values i so that all subintervals are accounted for Does the function pass the second test case? Error: You may not use the command(s) feval in your code Your Integral estimate for the Test 2 inputs was incorrect. Check your formulas for Delta and dI. Make sure you are creating a vector of n+1 points for x Does the function pass a random test case? Error: You may not use the command(s) feval in your code Your function did not return the correct value for a random interval and number of points Was Simpson's method used to compute the integral? Error. You may not use the command(s) feval in your code You must implement Simpson's method without using an existing MATLAB integrator function.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Simpsons Rule TIoteplatien Compaleo an inlayral via Amps le in the. Tr funetion cempules he inlegral via pr nis equally spa

Add a comment
Know the answer?
Add Answer to:
MATLAB Create a function that provides a definite integration using Simpson's Rule Problem Summar This example demo...
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
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