multiple functions within one script

5 views (last 30 days)
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);

Accepted Answer

Matteo Lo Preti
Matteo Lo Preti on 4 Oct 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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!