How to correct the error in code?
11 views (last 30 days)
ANCY S GEORGE on 2 May 2022
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?
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.