Not enough input arguments with fminunc

1 view (last 30 days)
I wrote the followng code
global y t;
y = [1 2 4 6 4 12 11 13 11 14 16 17]';
T = length(y);
t = [1:T]';
x0 = [0, 0];
x = fminunc(@ssr, x0);
and function
function val = ssr(a, b)
global y t;
val = (y - a - b*t)'*(y - a - b*t);
end
when I run the code I get not enpugh input arguments error. I do not understand the reason. Could you help?

Accepted Answer

Walter Roberson
Walter Roberson on 5 Jun 2019
x = fminunc(@(x) ssr(x(1),x(2)), x0);
  1 Comment
Yasin Simsek
Yasin Simsek on 5 Jun 2019
thank you very much. It works. But I wonder why my code does not work. And I do not see the input arguments that you used in the documentation. Where can I learn it? Could you tell me?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!