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