How to correct the error in code?
4 views (last 30 days)
Show older comments
ANCY S GEORGE on 2 May 2022
Commented: Rik on 30 Jan 2023
x = [x i];
y = [y i];
z = [z i];
While run this program an error shows
Index in position 1 exceeds array bounds.
Index must not exceed 1.
Failure in initial objective function evaluation. FMINCON cannot continue.
Sometimes it shows the error
Error using fmincon (line 641)
Supplied objective function must return a
How to correct this errors?What is the reason for this?
Rik on 30 Jan 2023
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.
Riccardo Scorretti on 2 May 2022
there is a macroscopic error in your code:
You defined an inline function F1 which is function of the variable A (which, by the way, is a matrix). I guess you wish to optimize this quantity with respect of x. However, a few lines after you requires A as result of the optimization, but you are passing x0 as starting point for the optimization; this is very confusing.
There is a second problem, which I'm afraid you have to solve by yourself. Assuming that the optimization variable is x, you are using x as index for a matrix. Hence x has to be an integer in the range [1 7] where 7 is the number of rows of A. You are optimizing x as a not necessarily integer value, with bounds [-100 100].
In other words, your program cannot work because the problem that you want to solve is badly formulated. You are the best person to know what you want to solve, so you have to reformulate clearly your own problem. Then we can support you to implement in MATLAB.
More Answers (0)
Find more on Problem-Based Optimization Setup in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!