multiple functions within one script

5 visualizaciones (últimos 30 días)
Nora Al Allaf
Nora Al Allaf el 4 de Oct. de 2020
Respondida: Matteo Lo Preti el 4 de Oct. de 2020
Hello :)
I'm trying to use a function inside another one
min_bisect is the first one and kastbana_5(x) is the second
[10,14], 1e-5 are just inputs built within min_bisect, 10 and 14 should be used as inputs in kastbana_5 but that's written in the min_bisect script
any idea how to make this work?
z = min_bisect(kastbana_5(x), [10,14], 1e-5);
tried this one: can't get an answer here either
z = min_bisect(@(x)kastbana_5(x), [10,14], 1e-5);

Respuesta aceptada

Matteo Lo Preti
Matteo Lo Preti el 4 de Oct. de 2020
Hi Nora,
You can have a function as input of another one, like this out = min_bisect(fun, a, b)
In the main call, use the pass it like a function handle @kastbana_5
Here you have a sample code:
z = min_bisect(@kastbana_5, 5, 5);
function out = min_bisect(fun, a, b)
x = a+b;
out = fun(x);
end
function y = kastbana_5(x)
y = x^2;
end

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by