## Using bisection to determine unknown parameter

### james carsley (view profile)

on 30 Jul 2019
Latest activity Answered by Kaashyap Pappu

### Kaashyap Pappu (view profile)

on 7 Aug 2019
Im using the code below to determine the value of 'w' , from the equation x(t)=(2fo/Wn^2-w^2)*sin((Wn-w/2)*t)*sin((Wn+w/2)*t) where f0=F0/m. Im using the bisection method algorithm to find the root with an absolute error of less than 1e-6. The programme runs but it gives me the naswer as 80 with an absolute error of 0.0000.
%Parameter Values
k=2000; %Stiffness units= N/m
m=0.405; %Mass units= Kg
F_0=4.05; %Applied Force Magnitude units= N
t=2.077; %Time units=s
x=0.010343; %Displacment units= m
f_0=(F_0/m);
% Q) Bisection method to determine w, with an absolute error of less
% than 1e^-6. When the displacement x=0.010343m at a time t=2.077s
% Limiting the useable values of w between 77<w(rad/s)<80
% Display the resulting value of w and the absolute eroor obtained
n=100;%number of bisection steps to be used
a=77; %first approximation
b=80; %second approximation
if function_Q2(a)*function_Q2(b)>0
disp('Wrong choice bro')
else
fprintf('Intial limits are incorrect, computer says no!\n');
a=input('Enter new first value for new interval:');
b=input('Enter new final value for new interval:');
end
r_error=0.1;
while r_error>1e-6
i=i+1;
est_root=0;
x_left=a;
x_right=b;
f_left=function_Q2(x_left);
f_right=function_Q2(x_right);
for m=i:n
x_mid=(x_left+x_right)/2;
f_mid=function_Q2(x_mid);
if f_left*f_mid<=0
x_right=x_mid;
f_right=function_Q2_mid;
elseif f_left*f_mid>0
x_left=x_mid;
f_left=f_mid;
end
est_root=(x_left+x_right)/2;
r_error=(x_right-x_left)/2;
fprintf('Estimate of root=%6.3f\n',est_root)
fprintf('Absolute error=%6.6f\n',r_error)
end
end
The function used for this:
function f=function_Q2(w)
k=2000; %Stiffness units= N/m
m=0.405; %Mass units= Kg
F_0=4.05; %Applied Force Magnitude units= N
t=2.077; %Time units=s
x=0.010343; %Displacment units= m
f_0=(F_0/m);
f=(((2*f_0)/((W_n^2)-(w^2))).*sin(((W_n-w)/2)*t).*sin(((W_n+w)/2)*t))-(x*t);
end
Any help would be much appreciated!

infinity

### infinity (view profile)

on 30 Jul 2019
Hello,
There is a point that make me confusing.
Why do you use "for" loop inside "while" loop?
Many examples of bisection methods are availables. You could refer, for example