not enough input arguments - fsolve and function handles

1 Ansicht (letzte 30 Tage)
LuC
LuC am 3 Jun. 2016
Bearbeitet: LuC am 6 Jun. 2016
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 ';']);

Antworten (1)

Torsten
Torsten am 3 Jun. 2016
coeff = fsolve(@(x)ts_7(x(1),x(2),x(3),x(4),x(5)), init, opts);
Best wishes
Torsten.
  5 Kommentare
Walter Roberson
Walter Roberson am 5 Jun. 2016
Please post your complete current code including the creation of opts.
LuC
LuC am 6 Jun. 2016
Bearbeitet: LuC am 6 Jun. 2016
run load_data.m
X = xdata;
opts = optimoptions('fsolve','InitDamping',0.005,'Algorithm','levenberg-marquardt'); % 'PlotFcn',@optimplotfirstorderopt);
init = [-1.3, 1.4, 4000, 0.12, 9]; % starting points
tic
coeff = fsolve(@(x)ts_7(x(1), x(2), x(3), x(4), x(5)), init,opts);
toc
B = coeff(1);
C = coeff(2);
D = coeff(3);
E = coeff(4);
Sv = coeff(5);
Y = D * sin (C * atan (B*X - E*(B*X - atan(B*X)))) + Sv;
plot(X, ydata, 'o', X,Y );
title('compare');
This is my code, ts_7.m function is the same as above.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by