Script for Calculating Undamped Oscillating Mass

3 visualizaciones (últimos 30 días)
Xander Juneau
Xander Juneau el 29 de Mayo de 2020
The problem that was posed is this:
The equation for an undamped oscillating mass is given by:
y ( t ) = (v0/ω)cos(ωt) + y0 sin(ωt)
  • y0 is the initial position of the mass in meters
  • v0 is the initial velocity in meters per second
  • ω n is the natural frequency in Hertz, defined as ω n = k m
  • k is the spring constant Newtons per meter
  • m is the mass in kilograms
The parameters of y 0, v0, k and m are arbitrary (that means you get to decide what the values are). Use any combination of input parameters to test your spreadsheet.
Create a MATLAB script to calculate values of y for 0 ≤ t ≤ 10 seconds, with increments of 0.2. Values for all unknowns should be requested from the user with the input() function. Print the results in a table using the fprintf() function.
Here is the code that I have written to answer this problem:
clear
clc
y_0 = input ('What is the initial Position in meters? : ');
v_0 = input ('What is the Initial Velocity in meters per second? : ');
k = 4500; % Newtons Spring Constant; set at 400 Newton-meters (N/m).
m = 50; % mass in kg, increments of 5 up to 260; total 50 increments.
t = [0:0.2:10]; % time in seconds (s) increments of 0.2 seconds up to 10.
w = sqrt(k/m); % calculating natural frequency in Hertz (Hz).
y_t = ((v_0/w) * cos(w* t)) + (y_0* sin(w * t));
fprintf ('Mass in kg Time in seconds(t) Initial Postition Position after time\n');
fprintf ('%10.0f\t%21.2f\t%20.3f\t%22.3f\n', [ m, t, y_0, y_t ]);
I am using arbitrary numbers for k and m. As the problem states t should be an array from 0 to 10 with increments of 0.2. I believe I have done that here? I believe maybe the problem is in the formatting of the table? When I run the script and get the table printed out in the command window looks like this:
What is the initial Position in meters? : 1
What is the Initial Velocity in meters per second? : 5
Mass in kg Time in seconds(t) Initial Postition Position after time
50 0.00 0.200 0.400
1 0.80 1.000 1.200
1 1.60 1.800 2.000
2 2.40 2.600 2.800
3 3.20 3.400 3.600
4 4.00 4.200 4.400
5 4.80 5.000 5.200
5 5.60 5.800 6.000
6 6.40 6.600 6.800
7 7.20 7.400 7.600
8 8.00 8.200 8.400
9 8.80 9.000 9.200
9 9.60 9.800 10.000
1 0.53 0.778 -1.026
-0 1.10 -0.588 -0.726
1 0.05 -1.086 0.647
1 -1.08 0.020 1.064
-1 -0.61 1.096 -0.090
-1 0.76 0.553 -1.111
0 1.01 -0.807 -0.491
1 -0.23 -0.975 0.855
0 -1.13 0.297 0.937
-1 -0.36 1.130 -0.365
-1 0.94 0.294 -1.128
0 0.85 -0.977 -0.225
1 -0.49 -0.804 1.010
Can anyone tell what is wrong with this? I would appreciate any feedback or pointers to resources to answer my problem.

Respuestas (0)

Categorías

Más información sobre Assembly en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by