Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How can I change my code instead of using the how close xl and xu are, I want to

ID: 3529181 • Letter: H

Question

How can I change my code instead of using the how close xl and xu are, I want to use relative error between old xr values and new xr values, how would I do that? thanks! function[Xr]=bisection1(Xl,Xu) % Problem 5.20 % Finding the Maximum Deflection E=50000; I=30000; wo=2.5; L=600; dy= @(x)((wo)/(120*E*I*L))*(-5*x^4+6*L^2*x^2-L^4); y= @(x)((wo)/(120*E*I*L))*(-x^5+2*L^2*x^3-L^4*x); %I hardly ever use the while loop but in this case it was surely needed % So I had to learn it, the while loop starts with a true statement about % the function then it interates until the it reaches the break statement while abs((Xu-Xl))>.0001 Xr=(Xl+Xu)/2; test=dy(Xl)*dy(Xr); if test< 0 Xu=Xr; elseif test > 0 Xl=Xr; else end end end

Explanation / Answer

THIS IS BISECTION FUNCTION THAT I MADE!!!

YOU ONLY NEED TO CHANGE THE MAIN EQUATION TO WHATEVER FUNCTION YOU WANT TO USE WITH!!!


HOPE YOU LEARN A LOT FROM THIS!!! :)

I AM PASSING THE ERROT LIMIT AS PARAMETER...YOU CAN REMOVE THAT AND USE CONSTANT LIMIT VALUE IN WHILE FUNCTION AS WELL!!!






function c = bisect(a, b, delta)



fa = f(a); %% compute initial values of f(a) and f(b)
fb = f(b);

%%if sign(fa) == sign(fb) %% sanity check: f(a) and f(b) must have different
%% signs
%%
%% the error function prints an error message and
%% exits
%%error('f must have different signs at the endpoints a and b. Aborting.')
%%end
fprintf('initial interval: a=%d, b=%d, fa=%d, fb=%d ',a,b,fa,fb)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%
%% main routine %%
%% %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

while ( abs(b - a) > 2*delta ) %% While the size of the interval is
%% larger than the tolerance

c = (b + a)/2; %% Set c to be the midpoint of the interval

fc = f(c); %% Calculate the value of f at c

if sign(fc) ~= sign(fb) %% If f(c) and f(b) are of different sign, then
%% f must have a zero between c and b (by the
%% Intermediate Value Theorem).
a = c; fa = fc;
else %% This is the case where f(a) and f(c) are of
%% different sign.
%%
b = c; fb = fc;
end
%% Repeat the algorithm on the new interval
fprintf(' a=%d, b=%d, fa=%d, fb=%d ',a,b,fa,fb)
end

function fx = f(x)
fx = 6*x^3 - 13*x^2 + x + 2; %% Enter your function here.
return;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote