confusing error message: 'Not enough input arguments'?

조회 수: 1 (최근 30일)
Valeri Aronov
Valeri Aronov 2021년 2월 24일
편집: Valeri Aronov 2021년 2월 27일
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
Valeri Aronov
Valeri Aronov 2021년 2월 27일
Thanks, Star. It was helpful, inlike Matlab's error message ;-(
Star Strider
Star Strider 2021년 2월 27일
As always, my pleasure!

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

채택된 답변

Star Strider
Star Strider 2021년 2월 24일
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.
.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by