not enough input arguments - fsolve and function handles
Show older comments
Hello,
I asked the similar question a few days back but I still couldn't solve the problem so now I changed the code but I keep getting an error that I have too many input arguments.
function eq = ts_7(A,B,C,D,E)
syms x
% dbstop if error
% primary coefficients
g = D * sin(C * atan( B*x - E * (B*x - atan(B*x)))) + A; % magic formula
eq5 = taylor(g, x, 'Order',1, 'ExpansionPoint',7) + 4296; % x^0
eq1 = taylor(g, x, 'Order',2, 'ExpansionPoint',7) - eq5 + 296.3; % x^1
eq2 = taylor(g, x, 'Order',3, 'ExpansionPoint',7) - eq1 - 79.77; % x^2
eq3 = taylor(g, x, 'Order',4, 'ExpansionPoint',7) - eq2 - 4.541; % x^3
eq4 = taylor(g, x, 'Order',5, 'ExpansionPoint',7) - eq3 - 0.03358; % x^4
x = 8;
eq{1} = matlabFunction(eq1) % syms to numeric function
eq{2} = matlabFunction(eq2)
eq{3} = matlabFunction(eq3)
eq{4} = matlabFunction(eq4)
eq{5} = matlabFunction(eq5)
end
and my main looks like this:
opts = optimoptions('fsolve','InitDamping',0.005,'Algorithm','levenberg-marquardt');
init = [-1.3, 1.4, 4000, 0.12, 9]; % starting points
tic
coeff = fsolve(@(init)ts_7(init), init, opts);
toc
Error:
Undefined function or variable "fuser".
Error in fsolve (line 257)
if ~isempty( isoptimargdbl('FSOLVE', {'F','J'}, fuser, JAC) )
Error in script_7 (line 11)
coeff = fsolve(@(x)ts_7(x(1), x(2), x(3), x(4), x(5)), init,opts);
Error in run (line 96)
evalin('caller', [script ';']);
Answers (1)
Torsten
on 3 Jun 2016
coeff = fsolve(@(x)ts_7(x(1),x(2),x(3),x(4),x(5)), init, opts);
Best wishes
Torsten.
5 Comments
Torsten
on 3 Jun 2016
Hi, why did you put x and not init(1),...,init(5)?
Because they are different.
"init" is an explicit vector of initial values while "x" is a formal argument to ts_7.
Best wishes
Torsten.
LuC
on 4 Jun 2016
Walter Roberson
on 5 Jun 2016
Please post your complete current code including the creation of opts.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!