(20*gc*exp(gd*x))/(gc + gd - gu) - (20*gc*exp(-x*(gc - gu)))/(gc + gd - gu)
That is a symbolic function involving three unbound symbolic variables together with the bound symbolic variable x.
fitfun = fittype( @(gc,gu,gd,x) D(x) );
@(gc,gu,gd,x) D(x) ignores the first three parameters passed into it, and invokes the symbolic function D passing in the fourth parameter passed to the function handle. D(x) will be calculated by substituting the passed x value into the symbolic function
(20*gc*exp(gd*x))/(gc + gd - gu) - (20*gc*exp(-x*(gc - gu)))/(gc + gd - gu)
which is going to return a symbolic expression involving the unbound symbolic variables gc, gd, gu .
When you have an anonymous function call that accepts named arguments, and calls a function without passing in the arguments, then those variables do not make it into the function. For example,
At the time that you execute
then MATLAB looks into the workspace at the time the anonymous function is being built, and copies the mentioned variables into the function handle, except for the ones on the parameter list. F would become a function handle with a hidden internal variable named A whose value was copied from A in the workspace. Any changes to A in the workspace after that do not change the value copied in. The function handle would effectively become @(B) 1+B . Then when you have the @(A,B) F(B), the first parameter passed in, A, does not affect the execution of F
This same rule applies for symbolic functions. When you have
then that is equivalent to
which assigns into the MATLAB workspace a reference to a variable named 'A' that lives inside the symbolic engine.
would then copy into the function handle the value of A, which is the reference to the 'A' that lives inside the symbolic engine. If you then change A inside the MATLAB workspace, then you do not change the execution of F.
Warning: Calling STRUCT on an object prevents the object from hiding its implementation details and should thus be avoided. Use DISP or DISPLAY to see the visible public
details of an object. See 'help struct' for more information.
and it would be that '_symans_[[32,0,42]]' internal reference that got copied into the function handle.
What you should be doing is:
fitfun = fittype( matlabFunction(D, 'vars', {[gc, gu, gd, x]}) );
Best Answer