A cubic polynomial is given by
$$y=\frac{x^3}{6RL}$$
with $R$ and $L$ being constants. Use Matlab and numerical methods to find $x_l$ so that
$$L=\int^{x_l}_0 \sqrt{1+(y')^2} dx$$
when $R=200$ and $L=170.$ Evaluate all the integrals by using the composite Simpson's rule.
Attempt
So if I understand this correctly, we need to use Simpson's rule to evaluate $x_l$ where
$$\int^{x_l}_0 \sqrt{1+(y')^2} dx = \int^{x_l}_0 \sqrt{1+ (\frac{x^2}{2RL})^2} dx= \int^{x_l}_0 \sqrt{1+ (\frac{x^2}{6800})^2} dx = L = 170$$
But I thought the method is used to estimate the integral, not the limits. Here's the code for the composite Simpson's rule:
function I = simpsons(f,a,b,n)
if numel(f)>1 % If the input provided is a vector
n=numel(f)-1; h=(b-a)/n;
I= h/3*(f(1)+2*sum(f(3:2:end-2))+4*sum(f(2:2:end))+f(end));
else % If the input provided is an anonymous function
h=(b-a)/n; xi=a:h:b;
I= h/3*(f(xi(1))+2*sum(f(xi(3:2:end-2)))+4*sum(f(xi(2:2:end)))+f(xi(end)));
end
What do I need to enter as the function? And what do I need to enter for $b$ (the last point of the interval, i.e. $x_l$)?
Any help would be greatly appreciated.
EDIT:
Code for the Bisection method:
a=0; b=170; tol=0.001;
f = sqrt(1+((x.^2)./68000).^2);
%Simpson's rule
if numel(f)>1
n=numel(f)-1; h=(b-a)/n;
I= h/3*(f(1)+2*sum(f(3:2:end-2))+4*sum(f(2:2:end))+f(end));
else
h=(b-a)/n; xi=a:h:b;
I= h/3*(f(xi(1))+2*sum(f(xi(3:2:end-2)))+4*sum(f(xi(2:2:end)))+f(xi(end)));
end
f = 170 - I;
%Bisection method
fa=feval(f,a); fb=feval(f,b);
while abs(b-a)>2*tol
m=(a+b)/2;
fm=feval(f,m);
if fa*fm<=0, b=m;
else a=m; end
end
For convienience write: $$ I(x)=170-\int_{0}^{x}\sqrt{1+\left(\frac{x^2}{68000}\right)^2}\; dx $$ Put $x_{l}=0$ and $x_{r}=170$. Then $I(x_{l})>0$ and $I(x_{r})<0$, so now you employ the bisection method to find $x_0\in (x_l,x_r)$ such that $I(x_0)=0$ using Simpsons rule to evaluate the integral involved in evaluating $I(x)$ at each step.
Matlab (or rather Gnu-Octave) code for the bisection method:
Of course you could use one of the built in root finders if you are allowed.
Running the computation from the command line:
Changing from n=100 to n=10000 in Simpson's rule less than doubles the computational time required.
The solution method can be improved somewhat if you send some time analysing the problem. It is quite obvious that the desired root is close to $x=170$, so starting with $0$ as the left hand limit for the bisection can be improved. But really unless you are in a production environment the time spent on further analysis is not really cost effective given how fast this executes as it is.