필터 지우기
필터 지우기

Inserting Functions into Bisection Method Code

조회 수: 2 (최근 30일)
Caleb Jones
Caleb Jones 2018년 3월 17일
I'm not having much luck here, I'm trying to play around with the bisection method and different functions.
I have working code I just need to know how to input the following function into the below code:
f(K) = tanh*K - F^2*K=0
Where K=2/F^2 and F=0.5
From Youtube and Google assistance I have the following code:
function RootFinder()
xU = 3; %Upper Bound
xL = 0; %lower Bound
%Setup Starting Point
xM = xL;
delx = (xU - xL)/2;
yn = myfunc(xM);
while abs(yn) > 1e-2 %%Threshold
xM = xM + delx;
yStar = myfunc(xM);
%%Set New Bounds If True
if sign(yStar) ~= sign(yn)
delx = -delx;
end
yn = myfunc(xM);
delx = delx/2;
end
function out = myfunc(in)
out = in.^2-2;
Thanks in advance!

답변 (1개)

Venkata Siva Krishna Madala
Venkata Siva Krishna Madala 2018년 3월 21일
편집: Venkata Siva Krishna Madala 2018년 3월 21일
Hello Caleb Jones,
I understand that you would want to know what myfunc should be rewritten.I have written the function below based on my understanding of the function you have given.
function out = myfunc(in)
out = tanh(in)-((in.^2)*in);
end
Regards,
Krishna Madala

카테고리

Help CenterFile Exchange에서 Manage Products에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by