i want to plot fragility curve stress vrs probability of failure and mean speed vrs probability of failure no of data is 48500

38 views (last 30 days)
% Load the data
filename = 'vehicle_data7.xlsx'; % Data file
data = readtable(filename); % Load the data into a table
% Beam properties
L = 40; % Beam length (m)
h = 2; % Beam height (m)
allowable_stress = 240e6; % Allowable stress in Pa (240 MPa)
g = 9.81; % Gravitational acceleration (m/s^2)
% Constants
rho_steel = 7850; % Density of steel (kg/m^3)
% Number of simulations (equal to number of rows in dataset)
num_simulations = height(data);
% Initialize counters for failures
failure_count = 0;
% Monte Carlo simulation loop
for sim = 1:num_simulations
% Extract vehicle data
vehicle_type = data.VehicleType{sim}; % Vehicle type (e.g., sedan, bus, truck)
weight = data.Weight_kN(sim) * 1e3; % Convert from kN to N
speed = data.Speed_km_h(sim) / 3.6; % Convert from km/h to m/s
spacing = data.Spacing_m(sim); % Spacing (m)
E_veh = data.Modulus_of_Elasticity_GPa(sim) * 1e9; % Convert from GPa to Pa
I_veh = data.Moment_of_Inertia_m4(sim); % Moment of inertia (m^4)
damping_ratio = data.Damping_Ratio(sim); % Damping ratio from dataset
% Beam's cross-sectional area and mass per unit length
b = I_veh * 12 / h^3; % Calculate beam width from moment of inertia
A = b * h; % Cross-sectional area (m^2)
m = rho_steel * A; % Mass per unit length (kg/m)
% Modal mass (corrected formula)
m_n = (m * L) / 2; % Modal mass (kg)
% Natural frequency for the first mode (omega_1)
omega_1 = sqrt((E_veh * I_veh) / (m_n * L^4)); % Natural frequency for first mode (rad/s)
% Stiffness for the first mode
k_1 = m_n * omega_1^2; % Modal stiffness (N/m)
% Critical velocity (m/s)
v_c = omega_1 * (L / pi); % Critical velocity
% Dynamic Amplification Factor (DAF) calculation
DAF = 1 / sqrt((1 - (speed / v_c)^2)^2 + (2 * damping_ratio * (speed / v_c))^2);
% Mode shape function for the first mode (phi_1)
phi_1 = @(x) sin(pi * x / L); % Mode shape for first mode (phi_1)
F_1 = weight * phi_1(L / 2); % Modal force due to moving load (N)
% Maximum displacement
w_max = (F_1 / k_1) * DAF; % Maximum dynamic displacement (m)
% Maximum stress (sigma_max)
phi_1_dd = @(x) -(pi^2 / L^2) * sin(pi * x / L); % Second derivative of phi_1
z = h / 2; % Distance from neutral axis to outer fiber (m)
M_max = -E_veh * I_veh * phi_1_dd(L / 2) * w_max; % Maximum bending moment (N.m)
sigma_max = M_max * z / I_veh; % Maximum dynamic stress (Pa)
% Compare sigma_max with allowable stress to determine failure probability
if sigma_max > allowable_stress
failure_count = failure_count + 1; % Increment failure counter
end
end
% Calculate failure probability
failure_probability = failure_count / num_simulations;
% Display results
fprintf('Number of Simulations: %d\n', num_simulations);
fprintf('Number of Failures: %d\n', failure_count);
fprintf('Failure Probability: %.4f\n', failure_probability);

Answers (1)

Walter Roberson
Walter Roberson on 29 Dec 2024 at 8:32
Edited: Walter Roberson on 29 Dec 2024 at 8:33
Your failure probability is a scalar. mean speed could be calculated as mean(data.Speed_km_h) but that would be a scalar. Plotting a scalar vs a scalar is a completely uninteresting plot.
You could conceivably
if sigma_max > allowable_stress
failure_count = failure_count + 1; % Increment failure counter
isfailure(sim) = true;
else
isfailure(sim) = false;
end
and then plot
scatter(data.Speed_km_h, isfailure)
I have to wonder, though, whether you should be doing something like discretize() Speed_km_h and accumarray() isfailure against discretized speed, and then bar plot the result.
  5 Comments
Walter Roberson
Walter Roberson on 30 Dec 2024 at 21:33
Your code defines probability of failure as failure_count / num_simulations . failure_count is not known until all of the entries in the data are analyzed. failure_count is inherently a scalar, so probability_of_failure is inherently a scalar.
There are three ways to plot a scalar against something else:
  1. plot() the scalar against another scalar, specifying a marker type. The end result will be only a single dot on the graph
  2. and 3. Use xline() or yline() to plot the constant scalar probability against the whole width or height of the graph. This graph is mostly useless.
Plotting the scalar probability of failure is mostly uninteresting.
Walter Roberson
Walter Roberson on 30 Dec 2024 at 21:37
% Load the data
filename = 'vehicle_data7.xlsx'; % Data file
data = readtable(filename); % Load the data into a table
% Beam properties
L = 40; % Beam length (m)
h = 2; % Beam height (m)
allowable_stress = 240e6; % Allowable stress in Pa (240 MPa)
g = 9.81; % Gravitational acceleration (m/s^2)
% Constants
rho_steel = 7850; % Density of steel (kg/m^3)
% Number of simulations (equal to number of rows in dataset)
num_simulations = height(data);
% Initialize counters for failures
failure_count = 0;
stresses = zeros(1, num_of_simulations);
% Monte Carlo simulation loop
for sim = 1:num_simulations
% Extract vehicle data
vehicle_type = data.VehicleType{sim}; % Vehicle type (e.g., sedan, bus, truck)
weight = data.Weight_kN(sim) * 1e3; % Convert from kN to N
speed = data.Speed_km_h(sim) / 3.6; % Convert from km/h to m/s
spacing = data.Spacing_m(sim); % Spacing (m)
E_veh = data.Modulus_of_Elasticity_GPa(sim) * 1e9; % Convert from GPa to Pa
I_veh = data.Moment_of_Inertia_m4(sim); % Moment of inertia (m^4)
damping_ratio = data.Damping_Ratio(sim); % Damping ratio from dataset
% Beam's cross-sectional area and mass per unit length
b = I_veh * 12 / h^3; % Calculate beam width from moment of inertia
A = b * h; % Cross-sectional area (m^2)
m = rho_steel * A; % Mass per unit length (kg/m)
% Modal mass (corrected formula)
m_n = (m * L) / 2; % Modal mass (kg)
% Natural frequency for the first mode (omega_1)
omega_1 = sqrt((E_veh * I_veh) / (m_n * L^4)); % Natural frequency for first mode (rad/s)
% Stiffness for the first mode
k_1 = m_n * omega_1^2; % Modal stiffness (N/m)
% Critical velocity (m/s)
v_c = omega_1 * (L / pi); % Critical velocity
% Dynamic Amplification Factor (DAF) calculation
DAF = 1 / sqrt((1 - (speed / v_c)^2)^2 + (2 * damping_ratio * (speed / v_c))^2);
% Mode shape function for the first mode (phi_1)
phi_1 = @(x) sin(pi * x / L); % Mode shape for first mode (phi_1)
F_1 = weight * phi_1(L / 2); % Modal force due to moving load (N)
% Maximum displacement
w_max = (F_1 / k_1) * DAF; % Maximum dynamic displacement (m)
% Maximum stress (sigma_max)
phi_1_dd = @(x) -(pi^2 / L^2) * sin(pi * x / L); % Second derivative of phi_1
z = h / 2; % Distance from neutral axis to outer fiber (m)
M_max = -E_veh * I_veh * phi_1_dd(L / 2) * w_max; % Maximum bending moment (N.m)
sigma_max = M_max * z / I_veh; % Maximum dynamic stress (Pa)
stresses(sim) = sigma_max;
% Compare sigma_max with allowable stress to determine failure probability
if sigma_max > allowable_stress
failure_count = failure_count + 1; % Increment failure counter
end
end
% Calculate failure probability
failure_probability = failure_count / num_simulations;
% Display results
fprintf('Number of Simulations: %d\n', num_simulations);
fprintf('Number of Failures: %d\n', failure_count);
fprintf('Failure Probability: %.4f\n', failure_probability);
plot(stresses, failure_probability, '*-')
The above code plots failure probability versus stresses. You will notice that the plot is mostly useless because failure probability is a scalar.

Sign in to comment.

Categories

Find more on RF Propagation 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!