Borrar filtros
Borrar filtros

Inserting Functions into Bisection Method Code

2 visualizaciones (últimos 30 días)
Caleb Jones
Caleb Jones el 17 de Mzo. de 2018
Editada: Venkata Siva Krishna Madala el 21 de Mzo. de 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!

Respuestas (1)

Venkata Siva Krishna Madala
Venkata Siva Krishna Madala el 21 de Mzo. de 2018
Editada: Venkata Siva Krishna Madala el 21 de Mzo. de 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

Categorías

Más información sobre Manage Products en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by