Error using symengine, Too many input arguments, x= xf; fx = funfcn(x,varargin{:});

12 views (last 30 days)
Hi,
could anyone help me with this problem?
I have this code:
a = 1;
b = 1;
c = 1;
d = 1;
e = 1;
f = 1;
func = @(x)(a.*x.^2 + b.*x + c)./(d.*x.^2 + e.*x + f);
syms y;
f_sym = (a.*y.^2 + b.*y + c) ./ (d.*y.^2 + e.*y + f);
df(y) = diff(f_sym, 2);
formulation = matlabFunction(formula(df));
minbnd = fminbnd(formulation, 0, 3);
And I get this error:
Error using symengine>@()0.0
Too many input arguments.
---
Error in fminbnd (line 232)
x= xf; fx = funfcn(x,varargin{:});
---
Error in Project (line 128)
minbnd = fminbnd(formulation, 0, 3);
Thanks for your help :)

Accepted Answer

Walter Roberson
Walter Roberson on 6 May 2022
with those constants, f_sym is (y*y + y + 1)/(y*y+y+1) which is 1 except at 0. derivative of 1 is 0... with no symbolic variables.
When you matlabFunction a constant expression and do not use the 'vars' option then it looks and sees no symbolic variables, and builds a function that accepts no parameters.
You should use 'vars', y for matlabFunction to get @(y)0.0 generated. That will not have an interesting minimum but it will not crash.
  2 Comments
Walter Roberson
Walter Roberson on 7 May 2022
formulation = matlabFunction(df, 'vars', y);
Remember that in context this is going to create a function that accepts a parameter and ignores it and returns a scalar 0.

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!