Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Root finding for multiple roots using bisection method

Status
Not open for further replies.

Canadianmech

Mechanical
Oct 6, 2005
1

I need help with the following root finding problem using the Bisection method

I want to find all roots between 0 and 3.5 for the following function:

y=sin(x^2)/e^(0.1*x) 0<x<3.5

I want a script to call the function three times to find these roots.

We know the 3 roots are between 1.5 and 2.0, 2.3 and 2.6, 2.9 and 3.2 so I want to use these for my right and left limits of x and be passed from the function to the bisection script.

I am having troubles with the function code and passing the left and right limits to the script. Here is what I have for script:


F_low=sin(x_low^2)/exp(x_low*0.1);
F_high=sin(x_high^2)/exp(x_high*0.1);
tolerance=0.01
F_x=100;

while abs(F_x) > tolerance
root=(x_low+x_high)/2;
F_x=sin(root^2)/exp(root*0.1);

if F_x*F_high > 0 % remove the right half of the interval because
x_high=root; % F_x and F_high have the same sign.
F_high=F_x;
else % remove the left half of the interval because
x_low=root; % F_x and F_low have the same sign.
F_low=F_x;
end
disp([x_low x_high F_x])

end


Here is what I have for the function:

function X=mybysection(x_low,x_high)


for i=1:3;
if i==1
x_low(i)=1.5
x_high(i)=2.0
elseif i==2
x_low(i)=2.3
x_high(i)=2.6
else
x_low(i)=2.9
x_high(i)=3.2
end
end


I'm unsure about the syntax to call these right and left limits into the script from the function
 
Replies continue below

Recommended for you

Why do you have to determine how you want the job done? Wouldn't you describe the problem and the application and those in the industry can provide you with their wisdom.
 
Matlab has various tools for root finding there is no need to write your own. Have a look at the help information for "fzero" (finds a root near the given starting value) and "fminbnd" (minimises a function between given bounds - you can use it to find roots by minimising the square of your function)

M

--
Dr Michael F Platten
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor