MATLAB Answers

0

Using bisection to determine unknown parameter

james carsley さんによって質問されました 2019 年 7 月 30 日
最新アクティビティ Kaashyap Pappu さんによって 回答されました 2019 年 8 月 7 日
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
W_n=sqrt((k/m)); %Natural Frequency units=Rad/s
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
W_n=sqrt((k/m)); %Natural Frequency units=Rad/s
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!

  1 件のコメント

infinity
2019 年 7 月 30 日
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

サインイン to comment.

1 件の回答

回答者: Kaashyap Pappu 2019 年 8 月 7 日

The results of function_Q2(a) and function_Q2(b) are negative, therefore no root exists within the interval [a,b]. The “if” condition is true, therefore the code should request new interval values within the “if” statement itself.
Alternatively, you can use the “linspace” function to generate an array of inputs between any interval as elaborated here, and input each value of the array to function_Q2 and observe outputs to find the zero crossing points, and select the two adjacent points for “a” and “b”.

  0 件のコメント

サインイン to comment.



Translated by