confusing error message: 'Not enough input arguments'?

1 Ansicht (letzte 30 Tage)
Valeri Aronov
Valeri Aronov am 24 Feb. 2021
Bearbeitet: Valeri Aronov am 27 Feb. 2021
Having:
function [f] = Simple(x)
f = (x(1)-1).^2 + (x(2)-1).^2;
end
and running:
x = lsqnonlin(Simple, [2.0, 2.0])
I am getting:
Not enough input arguments.
Error in Simple (line 2)
f = (x(1)-1).^2 + (x(2)-1).^2;
2 f = (x(1)-1).^2 + (x(2)-1).^2;
What is going on here?
  2 Kommentare
Valeri Aronov
Valeri Aronov am 27 Feb. 2021
Thanks, Star. It was helpful, inlike Matlab's error message ;-(
Star Strider
Star Strider am 27 Feb. 2021
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 24 Feb. 2021
With a function in that format, it is necessary to pass a function handle to lsqnonlin (or any other function that takes a function handle argument):
x = lsqnonlin(@Simple, [2.0, 2.0])
That is not the situation for anonymous functions that are already function handle objects:
Simple = @(x) (x(1)-1).^2 + (x(2)-1).^2;
x = lsqnonlin(Simple, [2.0, 2.0])
producing:
x =
1.000244655961070 1.000244655961070
See What Is a Function Handle? for details.
.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Objects finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by