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:
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 isStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started