Bisection method and numerical integration

In summary, the goal of this conversation was to find the upper limit of integration, ##x_l##, such that the value of the definite integral was 170. To achieve this, the composite Simpson's rule and the bisection method were discussed. However, the code provided was not functioning properly. An alternative method using the built-in numerical integrator quadl and the root finder fzero was suggested and shown to work.
  • #1
roam
1,271
12
In Matlab I am trying to use the composite Simpson's rule to find ##x_l## so that

$$170=\int^{x_l}_0 \sqrt{1+(y')^2} dx = \int^{x_l}_0 \sqrt{1+\left( \frac{x^2}{68000} \right)^2} dx $$

For convenience this can be written as

$$I(x) = 170 - \int^x_0 \sqrt{1 + (\frac{x^2}{68000})} dx$$

The limits of integration would be from ##0## to ##x=170##. Now to find the zero of this function I want to employ the bisection method while using Simpsons rule to evaluate the integral involved in evaluating ##I(x)## at each step.

Here's my code so far:

Code:
a=0; b=170;

for x=[0:]

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;tol=1e-6;
while abs(b-a) > tol
    x = (a+b)/2;
    y = ff(x);

    if y == 0
        rv = x;
        break
    end

    if ff(a)*y < 0
        b = x;
    else
        a = x;
    end
end

rv=(a+b)/2;

But I get lots of errors and the code does not run. I think it is because I need to get the Simpson's rule to calculate new value for the function at each midpoint of the bisection method. I'm not really sure how to fix this. :confused:

Alternatively, if bisection does not work with Simpson's method, I would appreciate it if anyone could show me how to exactly incorporate built in root finders into my code.

Any help would be greatly appreicated.
 
Last edited:
Physics news on Phys.org
  • #2
I'd use regula-falsi for the root finding part of this problem. If memory serves me correctly, MATLAB has a simpson's rule built in...
 
  • Like
Likes roam
  • #3
The question is confusing because first you say you are trying to find the upper limit of integration ##x_l## (such that the value of the integral is 170), but then later you say that the upper limit of integration is 170.

If you are trying to find the upper integration limit such that the value of the definite integral is 170, the following will work. quadl is a numerical integrator that comes with MATLAB, but you could also use quadgk or integral to the same effect. Also, fzero is the built-in root finder.

Code:
>> f = @(xl) quadl(@(x)sqrt(1+(x.^2/68000).^2),0,xl);
>> R = fzero(@(x) 170-f(x),4)
R =
  167.2340
>> quadl(@(x)sqrt(1+(x.^2/68000).^2),0,R)
ans =
  170.0000
 
Last edited:
  • Like
Likes roam and DrClaude

FAQ: Bisection method and numerical integration

What is the bisection method and how does it work?

The bisection method is a numerical method used to find the roots of a function. It works by repeatedly dividing a given interval in half and checking if the root lies within that interval. By narrowing down the interval, the root can be approximated with increasing accuracy.

What is numerical integration and why is it useful?

Numerical integration is a method used to approximate the definite integral of a function. It involves breaking down the area under a curve into smaller and simpler shapes, such as rectangles or trapezoids, and then summing up their individual areas. This method is useful when the integral cannot be evaluated analytically or when the function is too complex to be integrated by hand.

What are some advantages of using the bisection method for root finding?

One advantage of the bisection method is that it is guaranteed to converge to a root if the function is continuous and the root lies within the initial interval. It is also relatively simple to implement and does not require any initial guesses or derivatives of the function.

Are there any limitations to numerical integration?

One limitation of numerical integration is that the accuracy of the approximation depends on the number of subintervals used. With a large number of subintervals, the calculation can become computationally expensive. Additionally, numerical integration is only an approximation and may not give the exact value of the integral.

How does the bisection method compare to other root finding methods?

The bisection method is a relatively slow method compared to other root finding methods such as Newton's method or the secant method. However, it is more robust and does not require an initial guess or the calculation of derivatives. It is also guaranteed to converge, while other methods may not always converge or may converge to a wrong root.

Similar threads

Replies
8
Views
843
Replies
13
Views
2K
Replies
3
Views
1K
Replies
4
Views
2K
Replies
8
Views
2K
Replies
8
Views
2K
Back
Top