Optimtool not enough arguments

2 ビュー (過去 30 日間)
Yashwardhan Panwar
Yashwardhan Panwar 2020 年 3 月 8 日
回答済み: Koushik Vemula 2020 年 3 月 12 日
both while running the code and optimtool i get the error that not enough arguments
function ar = fun(a)
A=[8+a 1
2 3];
ar =det(A);
end
Error in the following problem input(s):
objective: Not enough input arguments.
  9 件のコメント
Yashwardhan Panwar
Yashwardhan Panwar 2020 年 3 月 9 日
i dont't know. Is there a way then to optimise a function?
Walter Roberson
Walter Roberson 2020 年 3 月 9 日
Yes, there are a number of ways to optimize a function. For example,
a_guess = randi([-1e6 1e6]);
best_a = fmincon(@fun, a_guess)
In the case of this particular function, the optimal would be -inf

サインインしてコメントする。

回答 (1 件)

Koushik Vemula
Koushik Vemula 2020 年 3 月 12 日
According to my understanding you are facing this problem because of the way you are trying to access the function.
You need to store your function in a separate ‘.m’ file (say XYZ.m)
Now you can call the function in this manner
XYZ(a) % a – your desired number
If you try to run a file which contains the definition of a function which has input arguments then you'll get those errors which you've faced

カテゴリ

Help Center および File ExchangeProblem-Based Optimization Setup についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by