- Randomly generate a state of charge (SOC) between 20% and 100% using a truncated normal distribution.
- Randomly generate a charging start time between 1 and 24 hours (also truncated normal).
- Randomly assign either Level 1 (L1) or Level 2 (L2) charging.
Help with Probability density functions?
5 views (last 30 days)
Show older comments
I need matlab script to randomly select a set percentage of electric vehicles owners out of a pool of customers. Then generate random data for those multiple users for their EV state of charge (20-80%) and the time of day they start charging their car based on probability density functions.
So out of a pool of 100 vehicle owners per se, it can randomly select a set percentage of owners who may have electricity vehicles (identifying 5 people for 5%). Then for those 5 ppl it gives corresponding state of charge and start charging time values for their EV. It can also randomize whether they charging at level 1 or 2.
So it selecting 5 numbers out of 1-100. Then selecting either L1 or L2. And then pulling a random value from density functions of state of charge 20-100% and charging time 1-24hr. I gotta determine the pdfs though. if we can use normal distributions to start The shape of the distribution should be based on data but we don't have any.I trying to l randomly generate scenarios for simulation.o the output of that statistical analysis would just input into the simulation Is just Monte Carlo with multiple variables?
0 Comments
Answers (1)
Ayush Aniket
on 8 May 2025
Yes, what you are describing is a Monte Carlo simulation where you randomly sample from specified distributions to generate scenarios for your simulation. Refer the steps and code snippet below ( using normal distributions as placeholders for the probability density functions):
1.Randomly select a specified percentage of EV owners from the customer pool:
% Parameters
num_customers = 100; % Total number of customers
percent_ev = 5; % Percentage of EV owners
num_ev = round(num_customers * percent_ev / 100);
% Randomly select EV owners
ev_indices = randperm(num_customers, num_ev);
2. For each selected EV owner:
% Preallocate results
ev_data = table(ev_indices', zeros(num_ev,1), zeros(num_ev,1), cell(num_ev,1), ...
'VariableNames', {'CustomerID', 'StateOfCharge', 'StartTime', 'ChargeLevel'});
% Distribution parameters (adjust as needed)
soc_mu = 50; soc_sigma = 15; % State of charge: mean 50%, std 15%
time_mu = 18; time_sigma = 3; % Start time: mean 18 (6pm), std 3 hours
for i = 1:num_ev
% State of charge (truncate to [20, 100])
soc = min(max(normrnd(soc_mu, soc_sigma), 20), 100);
% Charging start time (truncate to [1, 24])
start_time = min(max(normrnd(time_mu, time_sigma), 1), 24);
% Charging level (randomly choose L1 or L2)
if rand < 0.5
charge_level = 'L1';
else
charge_level = 'L2';
end
3. Stores the results in a table for easy use in simulations.
% Store results
ev_data.StateOfCharge(i) = soc;
ev_data.StartTime(i) = start_time;
ev_data.ChargeLevel{i} = charge_level;
end
Replace the normal distributions with your actual PDFs when you have empirical data.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!