Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to take my trapezoid rule code and adjust it keeping the same format to sole for the Simpson rule. I am just no

I need to take my trapezoid rule code and adjust it keeping the same format to sole for the Simpson rule. I am just no sure how to get this done. I have tried this and keep getting errors. Here is my trapezoid code. Thank You so much!

function s = myTrap(f,a,b,n)

x = linspace(a,b,n+1); %for n trapezoids, use n+1 points

h = (b-a)/n; s = (f(a)+f(b))/2; %initialize sum

%trap sum

for i = 2:n s = s + f(x(i));

end s = s*h; %multiply sum by h

when f= @(x)sqrt(1+x^3) from 1-4 with 20 traps I get 12.875041 for simpson the same function 1-4 should output 12.871490

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

Recommended Textbook for

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions