필터 지우기
필터 지우기

bisection method code help

조회 수: 2 (최근 30일)
Angelina Encinias
Angelina Encinias 2022년 8월 30일
댓글: Angelina Encinias 2022년 8월 31일
function root=bisection(func,x1,xu)
xr=x1;es=.0001;
while(1)
xrold=xr;
xr=(x1+xu)/2;
if xr~=0
ea=abs((xr-xrold)/xr)*100;
else
ea=100;
end
if func(x1)*func(xr)<0
xu=xr;
elseif func(x1)*func(xr)>0
x1=xr;
else
ea=0;
end
if ea<=es,break,end
end
root=xr;
end
  댓글 수: 2
Steven Lord
Steven Lord 2022년 8월 30일
What is your question or concern about the code you've posted and the text of (what appears to be) a homework problem?
Angelina Encinias
Angelina Encinias 2022년 8월 31일
What do I need to change to the code to fit the problem?

댓글을 달려면 로그인하십시오.

답변 (1개)

Sam Chak
Sam Chak 2022년 8월 31일
I did not change anything. The bisection code works for a simple test below to find :
fcn = @(x) sin(x) - 0.5; % if the equation is f(x) = g(x), then enter f(x) - g(x)
xL = 0; % lower bound
xU = pi/2; % upper bound
x = bisection(fcn, xL, xU);
x_deg = x*180/pi % solution in degree
x_deg = 30.0000
function root=bisection(func,x1,xu)
xr=x1;es=.0001;
while(1)
xrold=xr;
xr=(x1+xu)/2;
if xr~=0
ea=abs((xr-xrold)/xr)*100;
else
ea=100;
end
if func(x1)*func(xr)<0
xu=xr;
elseif func(x1)*func(xr)>0
x1=xr;
else
ea=0;
end
if ea<=es,break,end
end
root=xr;
end
  댓글 수: 1
Angelina Encinias
Angelina Encinias 2022년 8월 31일
Okay. Is this for my question above? I dont see anything about angles for this question.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by