Question: Below is some code used integrate an equation through the Simpsons rule in Freemat . I want to make it so I can calculate 10,000

Below is some code used integrate an equation through the Simpsons rule in Freemat. I want to make it so I can calculate 10,000 n values without having to type it 10,000 times. Right now the code works for 2 n values because of XRL and XRLL.

the Simpsons rule is as follows:

Below is some code used integrate an equation through the Simpsons rule

I need to change the "H" and add any code so no matter what the n value is it automatically uses the formula above to calculate with alternating 4 & 2 depending on the number of n's

Freemat Code:

format long

f = @(x) (4/(x^2 + 1))

a = 0

b = 1

n = 2

dx = (b-a);

H = 0;

for i = 1:1:n

xLL = a+(i-1)*dx;

xRL = a+4*(i+1)*dx;

xRLL = a+2*(i+1)*dx;

H = H +f(xLL)+f(xRL)+f(xRLL);

end

A = H*(dx/2)

Simpson's rule for estimating an area is

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!