## Inserting Functions into Bisection Method Code

Caleb Jones

### Caleb Jones (view profile)

さんによって質問されました 2018 年 3 月 17 日

### Venkata Siva Krishna Madala (view profile)

さんによって 編集されました 2018 年 3 月 21 日
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
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;

#### 0 件のコメント

サインイン to comment.

## 1 件の回答

2018 年 3 月 21 日

### Venkata Siva Krishna Madala (view profile)

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,