I have already declared some variable values as (for example):(adsbygoogle = window.adsbygoogle || []).push({});

a = 2

b = 3

Now I want to declare a function like:

f(x) = x + a - b

I will be optimizing w.r.t. x later, so I don't want to enter it as f(x,a,b)

(or is it possible to oiptimise w.r.t. just one of the variables?)

I tried

f = inline('x+a-b','x')

but then when I tried to evaluate it, it didn't have values for a and b (even though they were declared before!), so caused an error.

Any ideas? (other than defining the function with a and b replaced by value, because this won't allow me to change a and b later)

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# (Should be) Simple function declarations in Matlab

**Physics Forums | Science Articles, Homework Help, Discussion**