MATLAB Report ERC015
- Subject Code :
ERC015
- University :
Other Exam Question Bank is not sponsored or endorsed by this college or university.
- Country :
United Kingdom
MATLAB Report - Coursework
Student Name:
Student ID:
Course Code: ERC015
Module Leader:
Due Date:
Table of Contents
MATLAB Report (1)
Problem 3: Braking Performance
% Problem 3: Braking Performance
% This script calculates stopping distances of a race car under braking.
% The stopping distance is given by the equation: d = v^2 / (2a)
clear; clc; close all;
% 1. Define variables
% Initial speeds from 50 to 300 km/h in steps of 10 km/h
speeds_kmph =50:10:300;
speeds_mps =speeds_kmph * (1000/3600); % Conversion to m/s
?celeration values in m/s?2;
decelerations = [4,6,8,10]; % Different braking decelerations
% 2. Compute v?2; for all speed values
v_squared = speeds_mps.^2;
% 3. Calculate stopping distances for all combinationsa
% Initialize matrix: rows=speeds, columns=decelerations
stopping_distances = zeros(length(speeds_mps), length(decelerations));
for i = 1:length(decelerations)
a =decelerations(i);
stopping_distances(:, i) = v_squared ./ (2*a);
end
% 4. Extract stopping distances for specific speeds at a = 6 and 10 m/s?2;
target_speeds = [80,160,240]; % km/h
target_indices = find(ismember(speeds_kmph, target_speeds));
a6_index = find(decelerations==6);
a10_index = find(decelerations==10);
% Extract the corresponding stopping distances
stopping_selected_6 = stopping_distances(target_indices, a6_index)
stopping_selected_10 = stopping_distances(target_indices, a10_index)
% 5. Modify stopping distance at 200 km/h with a = 8 m/s?2;
% Increase it by 8%
index_200 = find(speeds_kmph == 200);
a8_index = find(decelerations == 8);
stopping_distances(index_200, a8_index) = ...
stopping_distances(index_200, a8_index) * 1.08;
% 6. Save the data in a .mat file
save('braking_data.mat', 'speeds_kmph', 'speeds_mps', 'decelerations', ...
'stopping_distances', 'stopping_selected_6', 'stopping_selected_10');
% 7. Plot stopping distance vs speed for each deceleration
figure;
hold on;
% Create a different marker for each deceleration
markers = {'o','s','d','^'};
colors = lines(length(decelerations));
for i = 1:length(decelerations)
plot(speeds_kmph, stopping_distances(:, i), ...
'LineWidth', 1.5, ...
'Marker', markers{i}, ...
'Color', colors(i,:), ...
'DisplayName', sprintf('a = %d m/s?2;', decelerations(i)));
end
grid on;
?d labels and legend
xlabel('Speed (km/h)');
ylabel('Stopping Distance (m)');
title('Stopping Distance vs. Speed for Various Decelerations');
legend('Location', 'northwest');
hold off;
MATLAB Report (2)
Matlab Function
function beam_analysis(L, P, w, E, I, c, sigmaY)
?AM_ANALYSIS Performs structural analysis of a cantilever beam
% beam_analysis(L, P, w, E, I, c, sigmaY) analyzes a cantilever beam
% with:
% L = Length of beam (m)
% P = Concentrated load at free end (N)
% w = Uniformly distributed load (N/m)
% E = Young's modulus (N/m?2;)
% I = Second moment of area (m?)
% c = Distance from neutral axis (m)
% sigmaY = Yield strength (N/m?2;)
% 1. Initialize variables and create position vector
n_points = 1000; % Number of points for analysis
x = linspace(0, L, n_points)'; % Position vector along beam
% 2. Preallocate arrays for results
M_x = zeros(n_points, 1); ?nding moment
sigma_x = zeros(n_points, 1); ?nding stress
delta_x = zeros(n_points, 1); ?flection
% 3. Calculate beam response at each point
for i = 1:n_points
?nding moment calculation
M_x(i) = -P*(L - x(i)) - (w/2)*(L - x(i))^2;
?nding stress calculation
sigma_x(i) = -(M_x(i)*c)/I;
?flection calculation
delta_x(i) = (P/(6*E*I))*(x(i)^3 - 3*L*x(i)^2) ...
- (w/(24*E*I))*(x(i)^4 - 4*L*x(i)^3 + 6*L^2*x(i)^2);
end
% 4. Check for failure (stress exceeds yield strength)
failure_points = find(abs(sigma_x) > sigmaY);
if ~isempty(failure_points)
warning(['Beam failure detected at ', num2str(length(failure_points)), ...
' points! Stress exceeds yield strength.']);
end
% 5. Create plots
% Common plot settings
line_width = 1.5;
% Figure 1: Bending Moment Diagram
figure;
plot(x, M_x, 'b', 'LineWidth', line_width);
title('Bending Moment Distribution');
xlabel('Position along beam (m)');
ylabel('Bending Moment (Nm)');
grid on;
% Figure 2: Bending Stress Distribution
figure;
hold on;
% Plot safe region as thick red line
safe_region = abs(sigma_x) <= sigmaY;
plot(x(safe_region), sigma_x(safe_region), 'r-', 'LineWidth', 3, 'DisplayName', 'Safe Region');
% Plot unsafe region as thick black dotted line (appearing as connected dots)
unsafe_region = ~safe_region;
plot(x(unsafe_region), sigma_x(unsafe_region), 'k.', 'MarkerSize', 12, 'DisplayName', 'Unsafe Region');
hold off;
% Customize plot appearance
title('Bending Stress Distribution', 'FontSize', 12, 'FontWeight', 'bold');
xlabel('Position along beam (m)', 'FontSize', 10);
ylabel('Bending Stress (Pa)', 'FontSize', 10);
% Set both axes to start from 0
xlim([0 L]);
ylim([0 max(abs(sigma_x))*1.1]);
% Configure legend and grid
legend('Location', 'northeast', 'FontSize', 9);
grid on;
box on;
% Figure 3: Deflection Curve
figure;
plot(x, delta_x, 'g', 'LineWidth', line_width);
title('Deflection of the Beam');
xlabel('Position along beam (m)');
ylabel('Deflection (m)');
grid on;
% 6. Parameter suggestions if failure occurs
if ~isempty(failure_points)
fprintf('nSuggested parameter modifications to prevent failure:n');
?lculate required scaling factor to stay within yield
max_stress = max(abs(sigma_x));
scaling_factor = max_stress / sigmaY;
% Option 1: Reduce loads
fprintf(' - Reduce P by %.1f%% and w by %.1f%%n', ...
(scaling_factor-1)*100, (scaling_factor-1)*100);
% Option 2: Increase beam properties
fprintf(' - Increase I by %.1f%%n', (scaling_factor-1)*100);
fprintf(' - Or increase c by %.1f%%n', (1-1/scaling_factor)*100);
% Option 3: Use stronger material
fprintf(' - Use material with E > %.2f GPan', E*scaling_factor/1e9);
end
end
Command Window
L = 5; P = 10000; w = 2000; E = 200e9;
I = 0.00000833; c = 0.05; sigmaY = 250e6;
beam_analysis(L, P, w, E, I, c, sigmaY);