These lines don't do what you think they do
syms x
g = 1.02*x + 0.6*exp(-8.7*x)-0.292
gx = @(x) g
The x in g is symbolic. The x in gx is a dummy input argument that is ignored because it isn't used in g. That is, the x dummy input argument in gx is different from the symbolic x in g.
It looks like you really want just a simple function handle:
gx = @(x) 1.02*x + 0.6*exp(-8.7*x)-0.292
E.g.,
>> gx = @(x) 1.02*x + 0.6*exp(-8.7*x)-0.292
gx =
function_handle with value:
@(x)1.02*x+0.6*exp(-8.7*x)-0.292
>> gval = 0.1;
>> guess = 0.5;
>> inv_fun = @(x) (gx(x) - gval)
inv_fun =
function_handle with value:
@(x)(gx(x)-gval)
>> S = fzero (@(x) inv_fun(x) , guess)
S =
0.3583
>> inv_fun(S)
ans =
-2.7756e-17
>> gx(S)
ans =
0.1000
If you insist on starting with a symbolic expression then you need to convert it to a function handle properly. E.g.,
>> gx = matlabFunction(g)
gx =
function_handle with value:
@(x)x.*(5.1e+1./5.0e+1)+exp(x.*(-8.7e+1./1.0e+1)).*(3.0./5.0)-7.3e+1./2.5e+2