maybe full version will be more usefull:
clear all
% VEHICLE DATA
M = 610; % weight [kg]
CdS = 1.035; % coefficient of drag * reference surface [m2]
ClS = 2.325; % coefficient of downforce * reference surface [m2]
h_cg = 0.25; % cg height [m]
W_d = 0.43; % percentage of weight at the front
W_b = 3; % wheelbase [m]
W_bf = W_b *(1-W_d); % distance front axle - cg [m]
W_br = W_b - W_bf; % distance rear axle - cg [m]
r = 0.33; % wheel radius [m]
f = 0.01; % rolling resistance coefficient (assuming drag force = M * f)
mu_lat_r = 1; % rear lateral friction coefficient
mu_lat_f = 1; % front laterl friction coefficient
% CONSTANTS
g=9.81;
rho = 1.22; % air density
% engine power curve X = rpm, Y = power [kW]
X = [13500,14500:500:18500];
Y = [452,485,517,536,548,558,570,580,588,593];
max_v = (2*max(Y)*1000/(rho*CdS))^(1/3); % theoretical max speed considering only aero drag
R = 500; % m radius
% nasty rearranged equation to find max cornering speed with aero downforce
top_bit = g*(W_br*musf+W_bf*musr)/W_b
long_bit = 0.5*rho*ClS*(W_br*musf+W_bf*musr)/(M*W_b)
bottom_bit = 1/R - long_bit % if long_bit > 1/R we end up with sqrt of negative number
% fraction = top_bit/bottom_bit
% spd = sqrt(fraction)
if long_bit > 1/R
disp('negative square route: flat out corner, treat as straight')
else
fraction = top_bit/bottom_bit
spd = sqrt(fraction)
if spd>max_v
disp('potential speed greater than max: flat out corner, treat as straight')
end
end
%
% if we have a flat out corner, we can treat it as a straight,
% so recalculate that sector as straight with length = original corner length
%
% if this means we have a straight followed by a straight, they can be combined to make one long straight
%
% if it is not a flat out corner then we can use the spd value to calculate time for that corner as before
% time = distance/speed
% for two consecutive corners we will still have to put up with a step change in vehicle speed.
%
% with corner speeds set we have entry & exit speeds for the straights.