- #1
uaeXuae
- 54
- 0
Hello guys can anyone help me solve this in MATLAB please ?
http://aycu34.webshots.com/image/43953/2003131790943491216_rs.jpg
http://aycu34.webshots.com/image/43953/2003131790943491216_rs.jpg
% bisection.m
function bisection
% find root of x^2 - 3 on some interval
xa = 0; xb = 10; % search interval
for it = 1:20 % loop
xtest = xa + (xb-xa)/2; % mid point of interval
fa = f(xa); % left-interval function value
fb = f(xb); % right-interval function value
ftest = f(xtest); % mid-point function value
if sign(fa)*sign(ftest)<0 % if zero in left half
xb = xtest; % take left half of interval
elseif sign(ftest)*sign(fb)<0 % if zero in right half
xa = xtest; % take right half of interval
elseif ftest ==0 % if zero at mid-point
break % this is the zero
else %
error('multiple roots or no root') % may have no zero or multiple zeros
end
xit(it) = xtest; % store mid-points
end
figure;plot(xit) % plot mid-points, should converge to the root
function y = f(x) % function we're finding the root of
y = x^2-3;
uaeXuae said:Q1) How do i input the equation ? Wherever it says "y = x^2-3" i replace it with the equation in the problem ?
Q2) how do i get an error<0.00005
The bracketing method in Matlab works by first selecting two initial guesses for the root of a given equation. These two values, a and b, must have opposite signs. The algorithm then calculates the midpoint between a and b, and checks if the midpoint is closer to the root than either a or b. If it is, then the new interval for the next iteration becomes [a, c], where c is the midpoint. If the midpoint is not closer to the root, then the new interval becomes [c, b]. This process is repeated until the desired accuracy is achieved.
The bracketing method in Matlab is used to find the roots of a given equation. It is a numerical method that is used to approximate the locations of roots. The bracketing method is particularly useful when the root of an equation is known to exist within a certain interval, making it a more efficient method compared to other root-finding algorithms.
The accuracy of the bracketing method in Matlab depends on the initial guesses for the root and the number of iterations performed. The algorithm will continue to refine the interval until the desired accuracy is achieved. However, if the interval is too large or the initial guesses are too far from the actual root, the algorithm may not converge to the correct root or may take a longer time to do so.
No, the bracketing method in Matlab is not suitable for all types of equations. It can only be used for equations where the root is known to exist within a certain interval and the function changes sign at the root. If these conditions are not met, the bracketing method may not converge to the correct root or may not converge at all.
Yes, the bracketing method in Matlab can handle multiple roots. However, the algorithm may only converge to one of the roots depending on the initial guesses and the function itself. If the initial guesses are close to multiple roots, the algorithm may converge to the one with the largest magnitude. To find all roots of an equation, multiple initial guesses and iterations may be needed.