Q:

Calling a function of X in Matlab

(I Have seen some answers to a similar question, but they didn't really answer what was being asked so ill try to explain it a bit better than the other questions)
title is not too informative but pretty much I'm trying to write a matlab script, to complete various repetitions of the bisection method, (not really important to my question, but its a method to find the root of a mathematical function.) 
The problem I'm having is that at the moment i can't figure out how to call my script for different functions. At the moment i have to write each function into the script and for each new function i have to change the script around. 
I want to call my function like bisection(f(x),a,b,N) (don't worry about a,b,N) so that i can choose the function when i call it rather than in the script itself. But when i write my f(x) as something like x^2 +x, it tries to evaluate it for a x that does not exist and returns a error. Is there anyway to call a function of x and leave it as a function so that later i can evaluate it at different values. 
   e.g. f(2)=6, f(a)=a^2 +a, f(b)=b^2 +b.

A:

You should use function handles.
Let's take an example : 
%Here f is the function you want to call
function M = testfun(f,x)
    M = f(x);
end

Then, to call it, you put as an argument a function handle
f = @(x) magic(x);
M = testfun(f,3)
M =

     8     1     6
     3     5     7
     4     9     2

