You are on page 1of 7

ENED 1091 HW#3

Due on Recitation Day Week of February 23rd


Problem 1: The graph below shows position measurements (in cm) collected every 0.5 seconds
over a 10 second interval of time.
(a) Using linear interpolation, estimate the position of the object at 2.45 seconds. Do this by
hand (no interp1) and show your calculations.
Calculation and Result (include units):
m=(7cm-4cm)/(2.5sec-2sec)
m=6 cm/sec
y=4+6(2.45-2)
y=4+2.7
y=6.7 cm
(b) Now use interp1 and linear interpolation to estimate the position of the object at 2.1, 2.2,
2.3, and 2.4 seconds.
MATLAB Command and Results (include units):
interp1([2 2.5],[4 7],[2.1:0.1:2.4],'linear')

ans =

Position (cm)

4.6000 5.2000 5.8000 6.4000


4.6 cm at 2.1 sec, 5.2 cm at 2.2 sec, 5.8 cm at 2.3 sec, and 6.4 cm at 2.4 sec
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0

Position Measurements

0.5

1.5

2.5

3.5

4.5 5 5.5
Time (sec)

6.5

7.5

8.5

9.5 10

Problem 2: For this problem, you need the excel file, HW3.xlsx posted on the Blackboard
Metasite under Homework Assignments, HW#3. The excel file has a vector of times, t, which
starts at 0 increments by 0.001 and ends at 0.015 seconds. It also has a vector of voltage

measurements, V, corresponding to the given times. Import both columns into MATLAB using
the import tool or the xlsread command.
(a) Use interp1 with a method of nearest to estimate the voltage every 0.0001 seconds between
0 and 0.015 seconds. On the same plot (not subplot), plot the original data points as red stars
and the interpolated data points as black circles.
MATLAB Commands and Plot
t_int=0:0.0001:0.015;
nearest=interp1(t,V,t_int,'nearest');
plot(t_int,nearest,'ko',t,V,'r*')
xlabel('time (sec)'); ylabel('Voltage'); title('Nearest Point Interpolation')

Nearest Point Interpolation

5
4
3
2

Voltage

1
0
-1
-2
-3
-4
-5

0.005

time (sec)

0.01

0.015

(b) Use interp1 with a method of linear to estimate the voltage every 0.0001 seconds between 0
and 0.015 seconds. On the same plot (not subplot), plot the original data points as red stars
and the interpolated data points as black circles.
MATLAB Commands and Plot
t_int=0:0.0001:0.015;
linear=interp1(t,V,t_int,'linear');
plot(t_int,linear,'ko',t,V,'r*')
xlabel('time (sec)'); ylabel('Voltage'); title('Linear Interpolation')

Linear Interpolation

5
4
3
2

Voltage

1
0
-1
-2
-3
-4
-5

0.005

time (sec)

0.01

0.015

(c) Use interp1 with a method of spline to estimate the voltage every 0.0001 seconds between 0
and 0.015 seconds. On the same plot (not subplot), plot the original data points as red stars
and the interpolated data points as black circles.
MATLAB Commands and Plot
t_int=0:0.0001:0.015;
spline=interp1(t,V,t_int,'spline');
plot(t_int,spline,'ko',t,V,'r*')
xlabel('time (sec)'); ylabel('Voltage'); title('Spline Interpolation')
Spline Interpolation

5
4
3
2

Voltage

1
0
-1
-2
-3
-4
-5

0.005

time (sec)

0.01

0.015

(d) What kind of waveform does your plot in part (c) look like? Could you possibly have picked
this up from looking at the original data points?
This looks like a sine wave. This could have been determined from looking at the original
data points because the points started and ended at zero, and they oscillate between 4.7553
and -4.7553, following the increase and decrease of a sine wave.

Position (cm)

Problem 3: The graph below shows position measurements (in cm) collected every 0.5 seconds
over a 10 second interval of time.
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0

Position Measurements

0.5

1.5

2.5

3.5

4.5 5 5.5
Time (sec)

6.5

7.5

8.5

9.5 10

(a) Using a t = 0.5 sec, estimate the velocity at t = sec using the 2-point estimate and the 3point estimate for the derivative. Be sure to show your work and include units!
2 Point Velocity= (7cm-4cm)/0.5sec
2 Point Velocity=6 cm/sec

3 Point Velocity=(10cm-4cm)/(2*0.5sec)
3 Point Velocity=6 cm/sec

2-point Estimate of Velocity at t = 2.5 sec: ___6 cm/sec______


3-point Estimate of Velocity at t = 2.5 sec: ___6 cm/sec______
(b) Using the estimate for 2nd derivative and a t = 0.5 sec, estimate the acceleration at t = 2.5
sec. Again, show work and include units!
Acceleration=(10cm 2*7cm + 4cm)/0.5sec^2
Acceleration=0 cm/sec^2
Estimate of Acceleration at t = 2.5 sec: _0 cm/sec^2_____
(c) What could be changed to improve the accuracy of the derivative estimates?
Use a smaller increment, t, to increase the accuracy.

Problem 4: An exponentially decaying sinusoid can be used as a mathematical models for


several applications including damped harmonic motion, damped vibrations in structures, and
filters. The general form for an exponentially decaying sinusoid is:

Suppose we have a mass connected to a spring. The spring is compressed 1 cm then released.
Based on the characteristics of the mass and spring, we determine that the displacement of the
mass from equilibrium (in cm) is:

We would like to determine how often we will need to take measurements of the displacement in
order to be able to get a good estimate for the velocity of the mass.
Write a script file that will do the following:
Prompt the user for a DeltaT value
Create a time vector ranging from 0 to 15 seconds with an increment of DeltaT.
Calculate the displacement measurements at the corresponding times in the time vector.
Create a second time vector ranging from 0 to 15 seconds with an increment of 0.001.
Calculate actual displacement using this second time vector.
Use the subplot command to subdivide the figure window into a top and bottom plot.
On the top plot, plot both actual displacement and displacement measurements.
Using the displacement measurements and DeltaT, estimate the velocity using the 2-PT
estimate.
Calculate the actual velocity from 0 to 15 seconds using the finer time increment of
0.001.
In the bottom plot, plot actual velocity and the 2PT estimate of velocity.
Add title, labels (with units), and a legend to each of your plots.
Run the script using a DeltaT = 1. Paste the plot below.
PLOT for DeltaT = 1

Displacement over Time

Displacement (cm)

"Actual" Displacement
Displacement "Measurements"

0.5
0
-0.5
-1

Velocity (cm/sec)

time (sec)
Velocity over Time

10

15

"Actual" Velocity
2 Point Velocity
0

-5

time (sec)

10

15

Run the script using a DeltaT = 0.5. Paste the plot below.
PLOT for DeltaT = 0.5
Displacement over Time

Displacement (cm)

"Actual" Displacement
Displacement "Measurements"

0.5
0
-0.5
-1

Velocity (cm/sec)

time (sec)
Velocity over Time

10

15

"Actual" Velocity
2 Point Velocity
0

-5

time (sec)

10

15

Now determine a DeltaT value that will produce accurate estimates for velocity keeping in mind
that smaller DeltaT values mean more measurements must be taken and computations must
be completed in a shorter time frame. In the space below indicate your choice of DeltaT and
also paste the corresponding plot.
PLOT for DeltaT = ___0.01 sec__________

Displacement over Time

Displacement (cm)

"Actual" Displacement
Displacement "Measurements"

0.5
0
-0.5
-1

Velocity (cm/sec)

time (sec)
Velocity over Time

10

15

"Actual" Velocity
2 Point Velocity
0

-5

time (sec)

10

15

PASTE SCRIPT HERE:


DeltaT=input('Enter the Delta T value: ');
t1=0:DeltaT:15;
d_measure=exp(-0.2*t1).*cos(5*t1);
t2=0:0.001:15;
d_actual=exp(-0.2*t2).*cos(5*t2);
subplot(2,1,1)
plot(t2,d_actual,t1,d_measure)
xlabel('time (sec)'); ylabel('Displacement (cm)'); title('Displacement over
Time')
legend('"Actual" Displacement','Displacement "Measurements"')
for k=1:length(t1)
if k==1
Vel_2PT(k)=0;
else
Vel_2PT(k)=(d_measure(k)-d_measure(k-1))/DeltaT;
end
end
for k=1:length(t2)
if k==1
Vel_actual(k)=0;
else
Vel_actual(k)=(d_actual(k)-d_actual(k-1))/0.001;
end
end
subplot(2,1,2)
plot(t2,Vel_actual,t1,Vel_2PT)
xlabel('time (sec)'); ylabel('Velocity (cm/sec)'); title('Velocity over Time')
legend('"Actual" Velocity','2 Point Velocity')

You might also like