Why this happens
Most EV performance questions at student level come down to road-load physics integrated over a speed profile, which needs only arrays, a loop and a plot. Free libraries handle this well, and writing the model yourself teaches you exactly where each loss comes from instead of hiding it inside a block diagram.
What you need
Tools
- Laptop (Windows, macOS or Linux)
- Python 3 with a package manager
- A code editor or Jupyter notebook
Materials
- A drive cycle as a time-speed table (for example a standard Indian or international cycle from your syllabus)
- Vehicle parameters: mass, frontal area, drag coefficient, rolling resistance, wheel radius, efficiencies
Before you start
- A simulation is only as good as its parameters; label assumed values clearly and do not present them as measured data.
- Do not use simulation results to justify modifying a real vehicle's controller or speed limits; that is unsafe and can make the vehicle illegal.
Step by step
- 1
Install Python and create a project environment
Install a current Python 3 release and create a virtual environment for the project so library versions stay fixed. Inside it, install NumPy, pandas, SciPy and Matplotlib, and Jupyter if you like notebooks. Record the installed versions in a requirements file so a classmate or examiner can reproduce your setup exactly with one command.
Tip: Keep one environment per project; it avoids version clashes later.
- 2
Load a drive cycle
Put your drive cycle in a CSV file with time in seconds and speed in km/h. Read it with pandas, convert speed to metres per second and check the time step is uniform, usually one second. Plot speed against time and compare it with the published figure for that cycle to catch unit or column mistakes before you build anything on top of it.
- 3
Write the road-load equation
For each time step compute acceleration from the speed difference, then the tractive force as the sum of rolling resistance (mass times g times rolling coefficient), aerodynamic drag (half times air density times drag coefficient times frontal area times speed squared), grade force if you include slope, and inertial force (mass times acceleration, optionally with a rotating-mass factor). Keep every parameter in one clearly labelled dictionary.
- 4
Convert force to battery power
Wheel power is force times speed. When it is positive, divide by drivetrain and motor-inverter efficiency to get battery power; when negative (braking), multiply by a regeneration efficiency and cap it at a realistic limit, or set it to zero for a vehicle without regen. Add a constant auxiliary load if your vehicle has lights or electronics drawing steady power.
- 5
Integrate energy and compute Wh/km
Sum battery power times the time step to get energy in joules, convert to watt-hours and divide by the distance covered to get Wh/km. Divide usable battery energy by this figure to estimate range on that cycle. Print a short results table with distance, energy, Wh/km and estimated range so the numbers are easy to quote in a report.
- 6
Add a simple battery model
Model the pack as an open-circuit voltage that depends on state of charge, in series with an internal resistance. From battery power, solve for current each step, update state of charge and record terminal voltage. This shows voltage sag under acceleration and lets you check whether a chosen pack would hit its low-voltage cut-off on the cycle.
- 7
Plot and run sensitivity checks
Plot speed, battery power, current and state of charge on shared time axes. Then change one parameter at a time, such as mass or drag coefficient, and record how Wh/km moves. This sensitivity table is often the most useful result for a project, because it shows which design choices actually matter for your vehicle.
- 8
Validate and document
Compare your output with a known reference, such as a textbook example or the consumption you measured on a real ride, and explain any gap. Add comments, a README describing the equations and assumptions, and the requirements file. If you need detailed electrochemical behaviour later, an open-source battery modelling library can be added to the same environment.
How to tell it worked
Running the script produces a speed and power plot, a state-of-charge curve and a Wh/km figure that stays close to a reference case, and anyone with your requirements file can reproduce the same numbers.
Stop and call a technician if
- Your model gives physically impossible results (efficiency above 100 per cent, negative energy over a full cycle) and you cannot find the cause; check units with a teacher before using the numbers.
- You plan to log data from a vehicle by connecting to its wiring; use only standard read-only interfaces or the manufacturer's app, and leave the vehicle's electrics alone.
Questions
Can this replace MATLAB and Simulink for coursework?
For longitudinal energy models and battery equivalent circuits, yes. Some courses and companies still expect Simulink, so it is worth learning both if your syllabus uses it.
Which time step should I use?
One second matches most published drive cycles and is fine for energy estimates. Use a smaller step only if you model fast dynamics such as motor current control.
