Error using lsqcurvefit due to 'Not enough input arguments' to the function and an error relating to the initial values chosen

1 view (last 30 days)
This is my code
Fuel_Cons = @ (a, E_Speed, E_Torque, E_Temp) a(1)+(a(2)*E_Speed)+(a(3)*E_Torque)+(a(4)*E_Temp)+(a(5)*E_Speed.*E_Torque)+(a(6)*E_Speed.*E_Temp)+(a(7)*E_Torque.*E_Temp)+(a(8)*(E_Speed.^2))+(a(9)*(E_Torque.^2))+(a(10)*(E_Temp.^2))+(a(11)*E_Speed.*E_Torque.*E_Temp)+(a(12)*(E_Speed.^2).*E_Torque)+(a(13)*(E_Speed.^2).*E_Temp)+(a(14)*E_Speed.*(E_Torque.^2))+(a(15)*E_Speed.*(E_Temp.^2))+(a(16)*(E_Torque.^2).*E_Temp)+(a(17)*E_Torque.*(E_Temp.^2))+(a(18)*(E_Speed.^3))+(a(19)*(E_Torque.^3))+(a(20)*(E_Temp.^3));
Input = [E_Speed; E_Torque; E_Temp];
a0 = [1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1];
[a, resnorm] = lsqcurvefit(Fuel_Cons, a0, Input, Fuel_Flow);
and this is the error
Error using @(a,E_Speed,E_Torque,E_Temp)a(1)+(a(2)*E_Speed)+(a(3)*E_Torque)+(a(4)*E_Temp)+(a(5)*E_Speed.*E_Torque)+(a(6)*E_Speed.*E_Temp)+(a(7)*E_Torque.*E_Temp)+(a(8)*(E_Speed.^2))+(a(9)*(E_Torque.^2))+(a(10)*(E_Temp.^2))+(a(11)*E_Speed.*E_Torque.*E_Temp)+(a(12)*(E_Speed.^2).*E_Torque)+(a(13)*(E_Speed.^2).*E_Temp)+(a(14)*E_Speed.*(E_Torque.^2))+(a(15)*E_Speed.*(E_Temp.^2))+(a(16)*(E_Torque.^2).*E_Temp)+(a(17)*E_Torque.*(E_Temp.^2))+(a(18)*(E_Speed.^3))+(a(19)*(E_Torque.^3))+(a(20)*(E_Temp.^3))
Not enough input arguments.
Error in lsqcurvefit (line 195) initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in Fuel_Curve (line 4) [a, resnorm] = lsqcurvefit(Fuel_Cons, a0, Input, Fuel_Flow); Caused by: Failure in initial user-supplied objective function evaluation. LSQCURVEFIT cannot continue.
Any help solving this error would be much appreciated

Answers (1)

Star Strider
Star Strider on 9 May 2014
The ‘Not enough input arguments’ comes from lsqcurvefit passing one parameter argument and one independent variable argument to FuelCons. You have four input arguments.
You have to format your objective function correctly. The parameter vector has to be the first argument, and the independent variable the second. It’s difficult to read your code, but since Input appears to be a (3xN) matrix of independent variables, you need to write as your objective function:
FuelCons = @(a, Input) ...
then inside FuelCons, you need to rewrite it, replacing ESpeed with Input(1,:), and similarly for ETorque and ETemp changing to Input(2,:) and Input(3,:) in your code in FuelCons respectively.
This is not as difficult as it seems. In the MATLAB Editor, under the ‘NAVIGATE’ section, use the Find utility to do a search-and-replace for each, one at a time.
Assuming you have no other problems in your code, it should run with these changes.

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!