Inserting Functions into Bisection Method Code
2 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
回答 (1 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Graphics Object Programming についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!