Optimtool not enough arguments
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 8 Mär. 2020
Please show the code that invokes the optimization algorithm
Walter Roberson
am 8 Mär. 2020
By the way you can optimize that calculation as
ar = 3*a+22
Yashwardhan Panwar
am 8 Mär. 2020
Yashwardhan Panwar
am 8 Mär. 2020
Walter Roberson
am 8 Mär. 2020
How do you start the code running? Which buttons do you press or what do you type in?
Yashwardhan Panwar
am 8 Mär. 2020
Walter Roberson
am 8 Mär. 2020
Okay, so when you press the Run button when you are in the editor for fun.m, what value do you expect MATLAB to use for the variable a and why do you expect it to use that particular value?
Yashwardhan Panwar
am 9 Mär. 2020
Walter Roberson
am 9 Mär. 2020
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
Antworten (1)
Koushik Vemula
am 12 Mär. 2020
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
Kategorien
Mehr zu Problem-Based Optimization Setup finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!