Description
Catastrophic Vibration
NOTE: Plan to finish a few days early to avoid last minute hardware/software holdups for which no allowance is given.
Purpose: You are employed by an architecture company to write code for a building simulation. The company wants to model the start of the motion response of a tall building hit by strong winds that set it in vibration that builds up catastrophically. The following graph shows the vibration oscillations growing catastrophically in time (along the x-axis) over a large number of Oscillations:
The simulation must run on a PC in real time and is part of a larger simulation that includes the motion of other structures. Because it must run in real-time it is too time consuming to use the more accurate but slow math library functions, so your task is to investigate a less accurate but faster Maclaurin Series approximation for the start of the motion where a few terms might be adequate. The formula you will use for an approximation for the movement D of the top of the building in meters with time t in seconds after the vibration starts up is:
D(t) = etcos(t)
In this application you will investigate the series approximation to the motion for its accuracy over initial times up to 4 seconds after the start of the vibration.
Algorithm: Determine the Maclaurin Series approximation to D(t) = etcos(t) as a power series in t (all variables are doubles) as given in lectures up to the first 7 non-zero terms (you need 7 for the truncation error on 6 terms). Then as often as the user wishes to repeat, allow the user to choose the number of nonzero terms (from 1 to 6) in the series approximation and what range (between 0.0 and 4.0) of values of t to evaluate in 10 equal increments. For each value of t the Maclaurin series approximation is output together with the exact value from the math library. Also output the relative error in two ways:
1. % Relative Exact Error (%RExactE) by comparison with the exact value from the math library defined by:
% Relative Exact Error (%RExactE) =100*(exact value – series value)/exact value
2. % Relative Series Error (%RSerE) from the first truncated term defined by:
% Relative Series Error (%RSerE) =100*first truncated term/series value.
The sample output at the end shows you what is expected. Yours should be the same.
See the Marking Sheet for how you can lose marks (you definitely lose 60% if the series is wrong).
What to Submit : Use Blackboard to submit this assignment as a zip file (not RAR) containing only the single source code file (ass1.cpp). The name of the zipped folder must contain your name as a prefix so that I can identify it, for example for CST8219 using my name the file would be tyleraAss1CST8233.zip. It is also vital that you include the Cover Information (as specified in the Submission Standard) as a file header in your source file so the file can be identified as yours. Use comment lines in the file to include the header.
Before you submit the code,
• check that it builds and executes in Visual Studio 2015 as you expect – if it doesn’t build for me, for whatever reason, you get a deduction of at least 60%.
• make sure you have submitted the correct file – if I cannot build it because the file is wrong or missing from the zip, even if it’s an honest mistake, you get 0. There is a late penalty of 25% per day. Don’t send me the file as an email attachment – it will get 0.
Example Output
Evaluate the Maclaurin Series approximation to D(t) = exp(t)*cos(t)
1: Evaluate the series
2: quit
1
Evaluating the series
Please enter the number of (non-zero) terms in the series (1, 2, 3, 4, 5 or 6):
6
Please enter the range of t to evaluate in 10 increments (0.0 < t < +4.0): 4
MACLAURIN SERIES
t D(t) Series D(t) Exact %RExactE %RSerE
0.000e+00 1.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00
4.000e-01 1.37406e+00 1.37406e+00 1.97652e-05 1.89266e-05
8.000e-01 1.55048e+00 1.55055e+00 4.67032e-03 4.29392e-03
1.200e+00 1.20114e+00 1.20307e+00 1.60134e-01 1.42054e-01
1.600e+00 -1.64517e-01 -1.44626e-01 -1.37529e+01 -1.03598e+01
2.000e+00 -3.19683e+00 -3.07493e+00 -3.96409e+00 -3.17776e+00
2.400e+00 -8.66380e+00 -8.12842e+00 -6.58647e+00 -5.04175e+00
2.800e+00 -1.73567e+01 -1.54945e+01 -1.20181e+01 -8.63769e+00
3.200e+00 -2.99298e+01 -2.44907e+01 -2.22089e+01 -1.45779e+01
3.600e+00 -4.66622e+01 -3.28198e+01 -4.21772e+01 -2.39913e+01
4.000e+00 -6.71270e+01 -3.56877e+01 -8.80954e+01 -3.87420e+01
Evaluate the Maclaurin Series approximation to D(t) = exp(t)*cos(t)
1: Evaluate the series
2: quit
1
Evaluating the series
Please enter the number of (non-zero) terms in the series (1, 2, 3, 4, 5 or 6):
5
Please enter the range of t to evaluate in 10 increments (0.0 < t < +4.0): 3
MACLAURIN SERIES
t D(t) Series D(t) Exact %RExactE %RSerE
0.000e+00 1.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00
3.000e-01 1.28957e+00 1.28957e+00 2.90054e-05 2.69193e-05
6.000e-01 1.50381e+00 1.50386e+00 3.42722e-03 2.95478e-03
9.000e-01 1.52797e+00 1.52891e+00 6.19271e-02 4.96870e-02
1.200e+00 1.19546e+00 1.20307e+00 6.32890e-01 4.75767e-01
1.500e+00 2.78125e-01 3.17022e-01 1.22695e+01 9.75120e+00
1.800e+00 -1.52346e+00 -1.37449e+00 -1.08377e+01 -6.37877e+00
2.100e+00 -4.58972e+00 -4.12266e+00 -1.13290e+01 -6.22886e+00
2.400e+00 -9.39181e+00 -8.12842e+00 -1.55428e+01 -7.75156e+00
2.700e+00 -1.65013e+01 -1.34524e+01 -2.26649e+01 -1.00621e+01
3.000e+00 -2.66000e+01 -1.98845e+01 -3.37723e+01 -1.30505e+01
Evaluate the Maclaurin Series approximation to D(t) = exp(t)*cos(t)
1: Evaluate the series
2: quit
1
Evaluating the series
Please enter the number of (non-zero) terms in the series (1, 2, 3, 4, 5 or 6):
4
Please enter the range of t to evaluate in 10 increments (0.0 < t < +4.0): 2
MACLAURIN SERIES
t D(t) Series D(t) Exact %RExactE %RSerE
0.000e+00 1.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00
2.000e-01 1.19707e+00 1.19706e+00 -8.89291e-04 -8.91067e-04
4.000e-01 1.37440e+00 1.37406e+00 -2.46322e-02 -2.48351e-02
6.000e-01 1.50640e+00 1.50386e+00 -1.68929e-01 -1.72066e-01
8.000e-01 1.56107e+00 1.55055e+00 -6.78300e-01 -6.99693e-01
1.000e+00 1.50000e+00 1.46869e+00 -2.13156e+00 -2.22222e+00
1.200e+00 1.27840e+00 1.20307e+00 -6.26147e+00 -6.48811e+00
1.400e+00 8.45067e-01 6.89251e-01 -2.26066e+01 -2.12143e+01
1.600e+00 1.42400e-01 -1.44626e-01 1.98461e+02 -2.45453e+02
1.800e+00 -8.93600e-01 -1.37449e+00 3.49869e+01 7.04852e+01
2.000e+00 -2.33333e+00 -3.07493e+00 2.41176e+01 4.57143e+01
Evaluate the Maclaurin Series approximation to D(t) = exp(t)*cos(t)
1: Evaluate the series
2: quit
Reviews
There are no reviews yet.