Optimization Error for car model
2 views (last 30 days)
Show older comments
Dear All,
I am trying to optimised a few parameters to achieve minimum fuel consumption. My parameters include gear ratio, throttle, vehicle and driver mass and it must be within a speed limit of 40km/h.
However, when I tried to optimised those parameters, it showed matrix dimensions must agree and failure in initial nonlinear constraint function evaluation. I tried to search online but I cannot figured out what problem is that.
It would be great if someone can tell me what is wrong with my model.
Thank you very much.
Wei Kang Chang
4 Comments
Swarooph
on 19 Mar 2019
Hei Wei,
2 points here:
- I downloaded the files and incorporated the changes Walter has suggested (which are correct). Since these files are in the PreLoadFcn callback, they will be executed only when you open the model. After making these changes, did you close the model, reopen it and then tried again? When I do this, I am able to run the model to get the scope output as shown below. Can you try the same and see if you are just able to run the model first without the optimization?
![2019-03-19_10-54-00.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/209244/2019-03-19_10-54-00.png)
![2019-03-19_10-58-54.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/209245/2019-03-19_10-58-54.png)
Answers (1)
Swarooph
on 26 Mar 2019
The following seems to fix your problem but I don’t know if this is what you really wanted to do:
- Set FCMin to “Minimize the function output”. Originally it was set to be “Constrain function output to be <= 0”. Did you mean to constrain FCMin to be <=0 ? Does that make sense for the variable/function you are trying to optimize for which seems to be fuel consumption?
![2019-03-22_8-56-39.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/210458/2019-03-22_8-56-39.png)
- Once I do (1), I am able to run the optimization without issues. Note that I did terminate the optimization before it converged or terminated automatically just to show that it is able to run iterations and do optimization.
![2019-03-22_8-57-00.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/210459/2019-03-22_8-57-00.png)
![2019-03-22_9-00-50.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/210460/2019-03-22_9-00-50.png)
That fixes your error issue. But to be honest, I am not completely convinced you have set up this optimization problem correctly. At the very least, your speed profile needs to have a lower bound of zero so that the car doesn’t go backwards. I also don’t know if you are plotting the right value for fuel consumption cost (FCMin plot). Should it be an average metric? So, take mean of all the fuel consumption values over the drive cycle instead of an array of fuel consumption values? Just some thoughts for you to think about.
0 Comments
See Also
Categories
Find more on Vehicle Scenarios 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!