Optimization Error for car model

61 views (last 30 days)
Wei Kang Chang
Wei Kang Chang on 19 Mar 2019
Answered: Swarooph on 26 Mar 2019
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
Swarooph on 19 Mar 2019
Hei Wei,
2 points here:
  1. 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 2. After fixing the above issue, I used your session file and try to run the optimization. I was able to get a few initial runs but then got the error about a missing custom objective function as shown below. It seems like you are missing a MATLAB file or a custom objective function specification here. Either you may have forgotten to include it in your question or you may have not gotten this from the original source..
2019-03-19_10-58-54.png
Wei Kang Chang
Wei Kang Chang on 20 Mar 2019
Hi Swarooph,
Thank you for your reply. I have got the same result. And yeah I forgot to attach the FCmin file.

Sign in to comment.

Answers (1)

Swarooph
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
  • 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
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.

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!