Effacer les filtres
Effacer les filtres

Inserting Functions into Bisection Method Code

1 vue (au cours des 30 derniers jours)
Caleb Jones
Caleb Jones le 17 Mar 2018
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!

Réponses (1)

Venkata Siva Krishna Madala
Modifié(e) : Venkata Siva Krishna Madala le 21 Mar 2018
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

Catégories

En savoir plus sur Manage Products dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by