Minimizing a set of known values?
5 views (last 30 days)
Show older comments
Hi All,
I can attach the code I am working on if it helps but my question is more general than that. I am looking to minimize an output by optimizing one of the input variables, using a genetic algorithm. The catch is, I know the output variable is going to be a 20x50 array and one of those values is a minimum. I want to find the minimum of the output variable by optimizing the input variable but I keep getting the error message "Unable to perform assignment as left side is 1by1 and right side is 20x50". Any idea as to why I keep getting that, or would you need the code?
Edit: I have attached a zip file with all the files you need. They all need to be on the path. "expoSinWrapper" is the objective function needing to be minimized, and tof_1 and k2 are the variables that need to be optimised. "attempt_2" is the ga implementation, and "mapvariables" is just some mapping I am attempting. There is a lot of fluff from combinations I have tried to fix my own error, that I have commented out. In layman's terms I am trying to minimize M_Fuel, by optimising a combination of k2 and tof_1. I hope that is clear and helpful. The newest error is the assignation to k2,
k2 = x(2)
it says index exceeds array bounds, but from the documentation I thought you were allowed to do that for multi variable optimisation?
EDIT 2: I fixed the problem, it was in the initialisation of the GA. Now the problem is that the fval being returned is the abnormally high one I set for errors in the objective function, meaning there isn't an optimisation occuring. Apologies for the messy question. Can anyone help?
3 Comments
Aquatris
on 26 Jul 2018
Optimization algorithms expect a cost function that results in a scalar value, not an array. Since your function outputs 20x50 array, and GA expects a scalar, that might be the problem you are having. If you are only interested in the minimum value, just change your function to be optimized to output the minimum value within the 20x50 array.
Answers (0)
See Also
Categories
Find more on Genetic Algorithm 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!