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

Walter Roberson
Walter Roberson 2020년 3월 8일
Please show the code that invokes the optimization algorithm
By the way you can optimize that calculation as
ar = 3*a+22
Yashwardhan Panwar
Yashwardhan Panwar 2020년 3월 8일
function ar = fun(a)
A=[8+a 1
2 3];
ar =det(A);
end
Yashwardhan Panwar
Yashwardhan Panwar 2020년 3월 8일
i want to optimse in this way because this a test code i will be implementing the logic on a big matrix
Walter Roberson
Walter Roberson 2020년 3월 8일
How do you start the code running? Which buttons do you press or what do you type in?
Yashwardhan Panwar
Yashwardhan Panwar 2020년 3월 8일
With the code in the script i press the run button , then i get the error and then i launch the optimtool from the command window and after i run the optimisation then also i get the error
Walter Roberson
Walter Roberson 2020년 3월 8일
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
Yashwardhan Panwar 2020년 3월 9일
i dont't know. Is there a way then to optimise a function?
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일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

제품

질문:

2020년 3월 8일

답변:

2020년 3월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by