0% found this document useful (0 votes)
6 views4 pages

Usman Akbar NA Open Ended Lab

MATLAB

Uploaded by

Usman Akbar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Usman Akbar NA Open Ended Lab

MATLAB

Uploaded by

Usman Akbar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

BS-3304L Numerical Analysis Lab

Open Ended Lab Task


Name : Muhammad Usman Akbar
Roll No : ME-211057
Problem:

An automobile is moving in a straight line at variable velocity. The velocity of the automobile is
measured at different time intervals, but the time intervals are not equal.

The students are given a table of data that contains the time and acceleration measurements. The
students need to generate the velocity vs time and displacement vs time graphs for the automobile
using the data provided.

Data:

Time [s] Acceleration [m/s]


0 1
2 2
4 1
8 0
12 0
16 -1
18 -1
20 0
24 0
30 4
32 4
35 2
40 0
44 0
46 0
50 -4
55 -3
60 0

1. Use the data provided to generate the velocity vs time and displacement vs time graphs for the
automobile using an appropriate numerical integration method.

2. Use MATLAB to write a script that reads the data from the table, performs the integration, and
generates the velocity vs time and displacement vs time graphs.

3. Provide the script and the generated plots in your report.

4. Discuss why you used the selected method.


Code:
% Define the data
time = [0, 2, 4, 8, 12, 16, 18, 20, 24, 30, 32, 35, 40, 44, 46, 50, 55,
60]; % time [s]
acceleration = [1, 2, 1, 0, 0, -1, -1, 0, 0, 4, 4, 2, 0, 0, 0, -4, -3, 0]; %
acceleration [m/s^2]

% Initialize velocity and displacement arrays


velocity = zeros(size(time));
displacement = zeros(size(time));

% Trapezoidal integration
for i = 2:length(time)
% Calculate velocity using trapezoidal rule
delta_t = time(i) - time(i-1);
avg_acceleration = (acceleration(i) + acceleration(i-1)) / 2;
velocity(i) = velocity(i-1) + avg_acceleration * delta_t;

% Calculate displacement using trapezoidal rule


avg_velocity = (velocity(i) + velocity(i-1)) / 2;
displacement(i) = displacement(i-1) + avg_velocity * delta_t;
end

% Plot velocity vs time


figure;
subplot(2,1,1);
plot(time, velocity, '-o');
xlabel('Time (s)');
ylabel('Velocity (m/s)');
title('Velocity vs Time');

% Plot displacement vs time


subplot(2,1,2);
plot(time, displacement, '-o');
xlabel('Time (s)');
ylabel('Displacement (m)');
title('Displacement vs Time');

3)

4) I use the trapezoidal method in numerical integration because it


provides a simple and effective way to approximate the definite
integral of a function. The trapezoidal method divides the area under
the curve into trapezoids and calculates the sum of their areas to
estimate the integral.

The reason I use the trapezoidal method is that it strikes a balance


between accuracy and simplicity. It is relatively easy to implement and
provides reasonably accurate results, especially for functions that are
relatively smooth.

Compared to other numerical integration methods, such as the


midpoint rule or Simpson's rule, the trapezoidal method is often
preferred when the function is not well-behaved or when the interval
of integration is not evenly spaced.

Overall, the trapezoidal method is a versatile and widely used


technique in numerical integration due to its simplicity and
satisfactory accuracy for many practical applications.

You might also like