not enough input arguments - fsolve and function handles

조회 수: 1 (최근 30일)
LuC
LuC 2016년 6월 3일
편집: LuC 2016년 6월 6일
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 ';']);

답변 (1개)

Torsten
Torsten 2016년 6월 3일
coeff = fsolve(@(x)ts_7(x(1),x(2),x(3),x(4),x(5)), init, opts);
Best wishes
Torsten.
  댓글 수: 5
Walter Roberson
Walter Roberson 2016년 6월 5일
Please post your complete current code including the creation of opts.
LuC
LuC 2016년 6월 6일
편집: LuC 2016년 6월 6일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by