File Exchange

image thumbnail

MATLAB and Simulink Racing Lounge: Vehicle Modeling

version 4.1.1 (1.43 MB) by MathWorks Student Competitions Team
Simulink and Powertrain Blockset models for the Vehicle Modeling series


Updated 23 Sep 2020

From GitHub

View Version History

View license on GitHub

This entry contains files accompanying the MATLAB and Simulink Racing Lounge video "Vehicle Modeling, Part 1: Simulink"
[Video link:]
The entry also contains the models accompanying the MATLAB and Simulink Racing Lounge video "Vehicle Modeling, Part 2: Powertrain Blockset"
[Video Link:]
The Simulink models show how to represent vehicle dynamics and specific components using a power loss approach.
* A glider model shows how to model vehicle dynamics to obtain high level information about tractive force requirements for a given weight and drive cycle.
* A battery electric vehicle (BEV) model shows how to use a power loss approach to represent individual components, such as the electric motor.
* A combustion engine vehicle model is also included for additional reference.

The Powertrain Blockset models show how single blocks can represent component operation, e.g: battery, motor, engine, transmission, differential, etc. These models include a glider, a BEV, and a combustion engine vehicle.

Cite As

MathWorks Student Competitions Team (2021). MATLAB and Simulink Racing Lounge: Vehicle Modeling (, GitHub. Retrieved .

Comments and Ratings (120)

Pham Van Tuan

Veer Alakshendra

Hi Pham,
FTP75 is one of the drive cycles (velocity vs time data) for emission certification. We use this as a reference for the closed-loop simulation. The drive cycle is saved in the Model Workspace. To understand how to explore the data in the Model Workspace, please check out this video at 4:00:

Pham Van Tuan

hello, i am doing graduation topic on this subject. I don't understand what drive cycle source is. What is the FTP75 standard and where does that data come from. Hope everyone can help me explain. thanks

Nobu Iijima

Hi Shubham,

First, you need to understand the Two-Way Connection Block. It can be used by connecting two of these blocks together, but the lines between the blocks are used for connection and have no signal.

Therefore, if you want to log data, you need to get the data from the line beyond the Two-Way Connection Block.

Image ↓
Data A → Two Way Block1 - Two Way Block2 → Data A
Data B ← Two Way Block1 - Two Way Block2 ← Data B

In this case, if you want to get Data A, you will need to get the data from the line after the second Two Way Block.

To get the log, you can use the "To Workspace" block.

Please let me know if you still have questions. Thankyou

Shubham Dhurjad

Hi, I've studied the 'PTB_ConventionalModel.slx' . I need to explore all the results that I can get through the model. I cannot enable data logging as the signals are physical. Please tell me how to explore all the results like tractive force, power, energy, and other important parameters.

Sam Reinsel

Hi Shubham,

The C0,C1,C2 coefficients in the Driveline model are for calculating the losses in the driveline gearing. In the Driveline subsystem, There is an annotation in the "ConventionalVehicle/Driveline/DrivelineTorqueLosses" subsystem That outlines it as:

Tloss = C0 + C1*T_i_n/200 + C2*(S-2000)/2000

The engine BMEP is used to limit the maximum torque of the engine based on engine speed: and similarly fmep0, fmep1, and C2 are used to calculate the engine efficiency in the "ConventionalVehicle/Engine/CalculateEfficiency" subsystem. LHV is the lower heating value of the fuel, and is used to determine the fuel mass used.

For any variable, you can find its uses using the Simulink FInder. Our colleague Guy wrote a blog about using it to find variables or other text

Isaac Alpheus

Hi, I am having a problem when I am trying to give an inclination angle. Should the input be in degrees or radians ?
I tried both and I am getting an error.
'Derivative of state '1' in block 'Model/Battery/Integrator1' at time 7.3573467550443947 is not finite. The simulation will be stopped. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances) '

How can I fix this ? Please let me know.


Shubham Dhurjad

Hi, I'm studying the conventionalvehicle.slx model and have few doubts regarding the variables in the MDL structure . I'm not getting what those variables are for eg; In the MDL.Drivelinemodel ; what is C0,C1,C2. In the MDL.EngineModel; what is BMEPtbl, fmep0, fmep1, C2, LHV.
Please do tell me what these variables signifies.


Veer Alakshendra

Hi Boling,
Thanks for reaching out. The current model doesn't use any optimization methods. However, using Simulink Design Optimization you can find the optimize the vehicle parameters:
For your case, the best way would be to use the response optimization app that optimizes the model parameters to meet the design requirements and satisfy constraints. To learn more, please watch this how-to video:

boling shao

Hi, i'm studying the BEV model and try to build my own for school project. Is there any documentation avaliable, so i can study this model further. :)
I want to build a BEV model and optimise the parameter of motor and battery. May I know is there any optimising algorithm used in this model? Which one is it?

boling shao


hi, all i am completely new and no experience in matlab, i want to design an electric vehicle with in wheel motors with lpv torque vectoring controller, how do i go about this?, thanks. books videos one on one class are all welcome

Harsh Kumar

Isiaka Saliu

Please I need you to help me with with hybrid vehicle design

I also have problem loading these files in 2017a version that I use.. is there a downloadable 2017a version of files available?

Nobu Iijima

Hi Ahmad,

If you can create variables of ECE 15 cycle data, you can use the "signal builder" block to create a Driver Cycle.

1. Delete "Input" Block from the BEV Simulink window.
2. Click any white place in the model and type the word "Signal Builder" to create Signal Builder Block.
3. Connect the arrow from "Signal Builder" block to the "Driver" subfunction block.
4. Double click "Signal Builder" block to open "Signal Builder" window.
5. Click "Signal" tab on the top left of the window, click "new", "custom" and put the variables of ECE 15 cycle data to create Signal 2. Delete Signal 1.
6. Set the "Stop Time" on the top of the BEV Simulink window, the time must be the same time as your cycle data.
7. Click "MODEL" tab, "Model Settings" to open the Configuration Parameter and uncheck "Input" box, and click "OK".

Thank you

Ahmad Khadhraoui

I have a question about the cycle.
How can I change the cycle of the modelo to cycle ECE15?

Nobu Iijima

Hi Khadraoui,

You can find MDL in the Model Workspace.
but this time, MDL is not a variable like massVeh, it is a structure.

so How to check the inside variables in the MDL structure?

1. Click "Model Explorer" below the "MODELING" tab to open the Model Explorer window as we did before.

2. Click Model Workspace in the "Model Hierarchy" on the left of the Model Explorer window.

3. Drag "MDL" structure in Model Workspace and drop it to Base Workspace.
* Do not go to MATLAB Base Workspace. You can find the "Base Workspace" in the Model Hierarchy in the same window.

4. Go to MATLAB and check the "Base Workspace" in MATLAB. You can find the MDL structure in the Workspace, and you can see inside variables.

How to change the variable?

The easiest way to change "MDL.MotorModel.MaxTrqOut" is that you can simply ignore MDL structure, and create a new "Constant Block" with the number.
If you want to use a variable instead of the number, then create a new variable in your Model Workspace. Please make sure the "Constant Value" name in the block parameter is the same name as the variable you created in the Model Workspace, and once you save the model, from next time the model will use your new variable.

Thank you

khadraoui ahmed

Hi Nobu Iijima,
thank you for your help.
However, I have a question. I find many blocks have "MDL" for example: "MDL.MotorModel.MaxTrqOut"
can you explain to me the mean for that?

Nobu Iijima

Hi khadraoui,

Thank you for the question. We have used "Model Workspace" to set the initial values.
You can customize those initial values from "Model Workspace" such as the mass parameter.

1. Open BEV Simulink model
2. Click the “MODELING” tab from the top left corner of the window
3. Click “Model Explorer” just below the "MODELING" tab to open a new window.
4. Click “Model Workspace” in BEV. You can find BEV in “Model Hierarchy” on the left of the window.
5. Change the value of your massVeh from the list. You can find our initial values here, and customize the parameters.

Thank you.

khadraoui ahmed

i need to change the mass parameter but I can't. can you help me?

Sandeep Nair

How to model idle speed shutoff in glider model ,could anyone pls help

We have fixed the loop error issue in the PTB_ConventionalModel.slx model and updated the files. Please let us know if you face any issues.

李浚鼎 李

Yaser Rostamani

is anyone knows that how can i get the energy consumption in this model?

Veer Alakshendra

Hi Anish,
There is an algebraic loop in the model. Please drop us an email at and we will send you the updated files.

Anish Jamardhan

Im getting many errors sir can you please help me with this
Input data dependency violation due to action subsystems. See Subsystem Examples in the Simulink library for valid and invalid examples of action subsystems
Input ports (2, 3) of 'PTB_ConventionalModel/Driveline/Transmission/Clutch' are involved in the loop.
Component:Simulink | Category:Model error
Input ports (1, Action) of 'PTB_ConventionalModel/Driveline/Transmission/Ideal Fixed Gear Transmission/Ideal Fixed Gear Transmission/Locked' are involved in the loop.
Component:Simulink | Category:Model error
Input ports (1, Action) of 'PTB_ConventionalModel/Driveline/Transmission/Ideal Fixed Gear Transmission/Ideal Fixed Gear Transmission/Unlocked' are involved in the loop.
Component:Simulink | Category:Model error
Input ports (1, 2) of 'PTB_ConventionalModel/Driveline/Transmission/Ideal Fixed Gear Transmission/Ideal Fixed Gear Transmission/Merge1' are involved in the loop.
Component:Simulink | Category:Model error
Input ports (1) of 'PTB_ConventionalModel/Driveline/Transmission/Saturation' are involved in the loop.
Component:Simulink | Category:Model error
Input ports (1) of 'PTB_ConventionalModel/Engine/Unit Conversion1' are involved in the loop.
Component:Simulink | Category:Model error
Input ports (2) of 'PTB_ConventionalModel/Engine/Mapped SI Engine/Mapped Core Engine/Without Temperature Input/Mapped Core Engine/EngTrq Table' are involved in the loop.
Component:Simulink | Category:Model error
Input ports (1) of 'PTB_ConventionalModel/Driveline/Transmission/ifNoTorqueIn/Compare' are involved in the loop.
Component:Simulink | Category:Model error
Input ports (2) of 'PTB_ConventionalModel/Driveline/Transmission/Logical Operator' are involved in the loop.
Component:Simulink | Category:Model error

Nobu Iijima

Hi Ricard,

You can switch the different driving cycles.
If you want to create the driving cycles, "Drive Cycle Source" will help you.

and also we also have the "Drive Cycle Data" that you can use.

If you want to change the drive cycles in this model, please find "DrCycles" in the model.
it is the imported data of the drive cycle, and you can change the data from them.

Thank you

Ricardo Moruno

Hello. I want to know how to switch between the different driving cycles. I just don't know how.


Ahmed Mohsen

Derek Yang

It's cool, thank you.

Mirsad Bucak

Thanks for sharing these useful models.

Abhilash Tukkar

nikhil setty

nikhil setty

Hello all,
Thank you for the detailed yet simplified version of the powertrain and vehicle dynamics blocksets. My question is regarding the nature of the graph of the Engine RPM. When a graph is plotted of Engine RPM, gear #, engine torque v/s Time, the engine RPM seems to remain constant at ~4700 RPM throught the simulation.As per my understanding, the Engine RPM should vary with the load on the engine and the pedal position.An upper limit on the engine speed has been given of value 6000 RPM.Could you please explain why this is happening in the simulation ?

Khalid Alyami

Hello, thank you for the detailed videos and models. You provide us with a complete BEV model in the documentation. I can't find the model variables (.m file), (for example Vehicle mass etc)

qizhen lan

Natalie Gereluk

How to I get the powertrain blockset? I have sent emails requesting the free trial and no one has replied...... this model seems to be marketed to students but the components are very difficult to obtain!!

sarah bassem

What motor did you use for BEV? from where did u get tractive force equation?

Olasubomi Omowa

Alfonso Festa

Good evening, when I try to start the model PTB_ConventionalModel I receive the error: Input ports 1 and 2 are involved in a loop. How can I solve?

Suraj Singh

Hi Dinesh Reddy and Srivijayakolki P,

I think that you are in the wrong directory. Check you file "Glider Model" directory and have that as a current directory. Your file path should be active on MATLAB path strip, above command window.

ahmed masry

Getting an error "Failed to load Driver glider library", Can anyone help me out?

I am getting error - "Failed to load Driver glider library", can someone help me with this?

Prateek Gupta

hi christoph. thank you for the model. I would like to know how to edit the parameters like the drive cycles, battery attribute and many more. Look for an early reply

Vineeth A

I got it sir. I was not in that directory.

Vineeth A

Hey Christoph sir ,
Should we have to move "driver_glider_library.slx" to somewhere else ?
I am getting error now as "Failed to load Driver glider library"

Zipeng Wang

Hi Christoph, could you please tell me how did you derive the equation of "F_tr = (T_motor-T_loss)*(G/r_w) - F_B " which is used to describe the driveline in this video? where this equation comes from?

Md Shafiqul Islam

Mahmoud Salem

Ang Xian Jia

Hi Christoph, is it possible to include supercapacitor for your electric vehicle modelling? May you provide any references?

Raj Kumar Muniyandi

Hi, Thanks for the video. In the BEV Simulink model. Most of the battery and motor parameters are represented as a structure MDL. Can you tell me how to access them that information or structure?

Christoph Hahn

Hi Dimitrios,
these are the references we used in the project:
[1] Sun, Zongxuan, and Guoming Zhu. Design and control of automotive propulsion systems. Boca Raton, Fla: CRC Press, 2015. Print.
[2] "Dynamometer Drive Schedules.“ EPA. Environmental Protection Agency, 31 Jan. 2017. Web. Apr. 2017.
[3] Zhang, B, and Mi, C. (2011), “Charge-Depleting Control Strategies and Fuel Optimization of Blended-Mode Plug-In Hybrid Electric Vehicles”, IEEE Transactions on Vehicular Technology, Vol. 60, No. 4, May 2011.
Best, Christoph

Dimitrios Vogiatzis

Hello Christoph,
It will be very helpful for us to share the sourse of the mathematical equation of the ICE efficiency that is used for the fuel consumption calc in the combustion engine vehicle.
is it possible?
Thanks in advance!

Christoph Hahn

Hi Jeevinthiran, what you did absolutely made sense. I placed a unit delay-block in the feedback loop from driveline subsystem to engine subsystem to avoid an algebraic loop. Additionally, I needed to comment through the radps2rpm-block in the engine subsystem (was using 19b for that). Best, Christoph

Hello Christoph,
I am trying to use the conventional model from the powertrain blockset but when I run the model, I get the ' Input data dependency violation due to action subsystems' . The only way I have managed to solve this is by placing a memory block in between the engine speed output from the driveline to the input in the engine. However, the system runs very slowly. Is there a better way of solving this?

Ang Xian Jia

Thanks Sir Christoph Han for previous reply. I will slowly learn from the links.
For this model, may I know why there are negative values for motor power output and motor power input? I am trying to calculate efficiency from Sir's model and I'm getting negative efficiency values.

Christoph Hahn

Dear Ang Xian Jia,
yes what you want to do (motor and battery specifications, then output the drive cycle information) is absolutely feasible.
Allow me to refer you to two more resources:
#1 This will help you to model and parametrize batteries, which we didn't cover in detail:
#2 Some materials how to output and log drive data from a vehicle / powertrain model:
Hope this helps!
Best, Christoph

Girish babu P

Ang Xian Jia

Hi Sir Christoph,
Is it possible for us to input the motor and battery specifications, then output the drive cycle information, like speed,distance and range travelled? If yes, may you guide me on how to do it or any reference to refer to? Or is the method to solve the problem is quite same with the model done by you but in a reversing way of model?

Christoph Hahn

Hi Zeeshan,
we are referring to this paper: Zhang, B, and Mi, C. (2011), “Charge-Depleting Control Strategies and Fuel Optimization of Blended-Mode Plug-In Hybrid Electric Vehicles”, IEEE Transactions on Vehicular Technology, Vol. 60, No. 4, May 2011.
Hope this can be of help to you,
Best, Christoph

zeeshan gilani

Hello Christoph,
We are using your model for our 3kw BLDC motor and we would like to calculate the Kc, Kw& Ki constants for our motor model.Can you please tell us how did you derive the equation of Ploss= Kc*Torque^2 + Ki*w + Kw*w^3.
It will be really helpful if you can guide us through the process of deriving those constants and the equation.
Thank you.

Christoph Hahn

Hi Monal,
what model are you referring to?
Please send an email to We'll be happy to have a look.
Best, Christoph

Monal Gedam

Hello, Can anyone tell me what is w_max, and w_ref in the workspace and where it is used. Please help

mudhapaka pushkal

Hi Christoph Sir,
I want to model a BEV using induction motor in simulink , could you possibly guide me with the useful resources.

mudhapaka pushkal

Christoph Hahn

Hi Shashank,
Thanks for the notes! I am referring to both of your queries from 14 Aug (#1) and 5 Aug (#2).
#1 I am not entirely sure what exact model you are referring to. Could you please point me to it?
#2 Consider the PID block as 'driver' that tries to stick to the drive cycle. The block will always try to minimize the delta between, e.g. car speed and required speed (from drive cycle). Simulink is coming without units and brake as well as accelerator commands may have values between [0,1].

Shashank Bharadwaj

Hey, in your battery model the open circuit voltage remains constant throughout. Should't that change as a function of state of charge?

Harit Bajaj

Hey Christoph,
Could you possibly guide me to the equations used in the models or the slides that were mentioned in the video

Shashank Bharadwaj

Hello Mr. Chris. I would like to know in what units or nature is the PID output? In the first part of the video, the mph error is somehow processed and PID output a tractive force. I don't understand how that is achieved. Also, secondly can the PID output, which is the accelerator and brake command in the model, be the input to the electric motor? I want to use the drive cycle as a throttle input to my battery/model. Sorry, I'm pretty new to the software.

Christoph Hahn

Hi Kevin, I just downloaded the models and ran 'Driver_Glider.slx' exemplarily without any issue. Make sure your current folder in MATLAB is the one with the model. Hope this helps. Best, Christoph

Kevin Fernandes

Hi Christoph sir

I've downloaded the models but when I open them, the Canvas interface shows me the next error:
"Failed to load library 'Driver_Glider_Library' referenced by 'BEV/Driver "

how can I solve this problem?

Thankk you

Christoph Hahn

Hi William,
hereby I am linking a T-dependent battery model:
Hope that is relevant to you.

Christoph Hahn

HI Parth,
changing the drive cycle is straightforward. Just replace the drive-cycle that comes with the model. (It is stored in the model workspace: and replace it with something custom.

William McCullough

How would it be possible to make the battery temperature dependent? Such that the battery SOC is affected at different temperatures?

Parth Patel

How can one change the drive cycle? for Example NEDC ,WTP

Christoph Hahn

Dear Saksham, Thanks for your great feedback! You may of course cite this as internet resource.

Saksham Consul

Thank you for such a versatile model. I would like to cite this, can you please guide as to how I should go about doing it?

Thank you.

Veer Alakshendra

Hi Dinesh,

To answer your second question, it would be better if you could share the email with us on


Veer Alakshendra

Hi Dinesh,

The values are stored in the Simulink model workspace.
You may access it through Simulink toolbar -> View -> Model Explorer.
This link provides a bit more background:

In case you are still unable to find the data, drop an email to We will send you the screen shots via email.


Dinesh tej

Hii Christoph sir
I am not getting, should I add BEV model to that Existing 3D Animation or the Power train blocks which are available in the file exchange?

Dinesh tej

Hii Christoph sir
Can you Please tell me what is the Specifications of Battery, motor specifications and type of motor used here ?

Christoph Hahn

Hi Deepa,

some thoughts about the question you asked on March 30:
That inclination angle is used by the GradeForce[N] block, which calculates a force based on massVeh*gravity*sin(inclinationAngle). By default, the sin function in MATLAB takes angles as radians. To operate in degrees, then use massVeh*gravity*sin(deg2rad(inclinationAngle))
The negative speed value means reverse motion. This would happen if resistive forces (like grade) act on the vehicle before the tractive force can dominate the vehicle motion.

Hope this helps,
Best, Christoph

Christoph Hahn

Hi Dinesh Tej,

the model you are referring to is a simplified one. It takes into account the powertrain and the longitudinal dynamics. So e.g. lateral dynamics are entirely missing. It wouldn’t be very helpful to display this in 3D animation.

What you may want to do is the following.
1. Check out the Vehicle Dynamics Blockset including its examples. E.g. run this command >> vdynblksSceneCameraRayStart in the MATLAB Command Window. Thereby you get the 3D animation running.
2. Add the vehicle model features from this FileExchange submission to the model created in #1.

Hope this helps to get started.
Best, Christoph

Dinesh tej

How to add 3D animations to the your BEV model ?



Hi Christoph sir,
the inclination angle given is zero degrees in the modelling, when we change the angle to say 20 degrees the output velocity is getting started from -2.3 mph while the input is unchanged, can you please briefly describe what does that negative values interpret in the real time?

Hi Deepa, you may certainly give it an initial try using PID Tuner ( With respect to the vehicle model, the PID block is actually a (very simplified) representation of the vehicle. So you would want to tune it to mimick you actual vehicle. Same holds true for the driver. Via the PID block you can tune it to be more aggressive or relaxed. Best, Christoph


thank you Christoph sir.
And Can you please tell me how the PID constants are selected particularly for both driver glider(P-7500, I-1, D-0) and BEV system(P-250, I-1, D-0).

Hi Deepa, these are motor loss constants: k_c [s / kg m^2], ki [J], k_w [kg m^2]. In general, you could say that: P_loss = P_in - P_out. P_loss in our example is a function of p_in and is approximated by a quadratic equation with these constants: P_loss = C_0 + C_1 * P_in + C_2 * P_in^2. If you have test data about losses, I suggest you do your own regression / curve fitting to get the constants. If you don't have test data, you could start with an ideal (lossless) motor and estimate the impact of the error. Best, Christoph


Sir how to choose the constants like Kc, Ki, Kw etc. ?

Hi Yujie, I guess you are referring to the models of the physical modeling tutorial that we are mentioning in the video. Find them here: Hope this is what you are looking for. Best, Christoph

Yujie Hu

battery, motor, engine... models cannot be found in the zip file. Could you add them in? Thank you very much!

Xiaoyu Huang

Christoph Hahn

Hi Deepa Anand,
the drive cycle is stored in the Simulink model workspace.
You may access it through Simulink toolbar -> View -> Model Explorer.
This link provides a bit more background:
Best, Christoph


how I can access the drive cycle stored parameters?

lovedeep dhilon

Trung Quang Nguyen

Hi Josh,
good point! The data is accessible through the Simulink model workspace. See here a reference:
Hope that helps.
Best, Christoph

Josh Fleming

Hello, I'm confused how I can access the drive cycle and other similarly stored parameters. For instance, the Constant block contains DrCycles.US06. How do I access and view the data stored in US06? Normally I would look in the Matlab workspace but I don't see it.

OmarAlfarouq Alfazazi

said belhadj

salutations, je veux exploiter le modèle de véhicule électrique à batterie (BEV), mais je n'ai pas compris comment ils ont modelisé chaque bloc. est ce qu'il ya un ecrit explicatif de ce modele? merci.
Said Belhadj.


i dont have matlab 2018 latest version. I am using Matlab 2017 b Can you please export this to my version?

Samarth Shah


Thanks for sharing such nice model.
One minor note on engine rotational speed calculation in the conventional model (version 3.0):
inside the driveline subsystem, it is calculating omega by dividing Velocity [mph] by wheel radius [m], the velocity shall be converted from mph to mps before division.

Veer Alakshendra

Hi Vasudevan. If you are looking to convert a current model into an older version, we already have an answer on MATLAB Answers:
I would also encourage you to upgrade to the latest release.

Carlos Carmona

I downloaded the models but when I open them, the Canvas interface shows me the next error:
"Failed to load library 'Driver_Glider_Library' "
Can anyone help ?

Vasudevan Nambeesan

Hi, is it possible to release the files in an earlier version of MATLAB? Maybe r2015a? Thanks!


Christian Mansell

mahmoud nasser

how can i run this models with matlab 2016 a version ? it gives me an error because this models were created with different version.

Veer Alakshendra

Shehara Perera

when I run simulation I get errors
Warning: Could not evaluate MaskDisplay commands of block 'PTB_BatteryElectricVehicle/Battery/Datasheet Battery':
Undefined function 'autoicon' for input arguments of type 'char'.

can anyone help??

gökalp ayaz


MATLAB Release Compatibility
Created with R2018a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!