Code covered by the BSD License
-
analyseExperimentalData(inFil...
analyseExperimentalData :
-
comparePendulumToSHM(x0,k,m)
comparePendulumToSHM : compare the motion of a simple harmonic oscillator
-
makeSincMovie
Copyright 2008-2009 The MathWorks, Inc.
-
pendulumDE(tVals,omega0,start...
Copyright 2008-2009 The MathWorks, Inc.
-
pendulumDataSimulated(x0, pen...
Generate simulated pendulum data and write this to an Excel spreadsheet.
-
pendulumFitFunction(t,y,param...
pendulumFitFunction : returns the fit value of pendulum model to
-
pendulumSimulation(x0,g,len)
pendulumSimulation : Simulation of pendulum
-
plotFrequencySpectrum(sampleF...
Plot the frequency spectrum of simple harmonic motion
-
plotTimeSeries(res)
Plot the time series representation of simple harmonic motion
-
readExperimentalData(inFileNa...
readExperimentalData : Read in the pendulum experiment data from an Excel
-
shmDataSimulated(x0, springCo...
Generate simulated pendulum data
-
shmSimulation(x0,k,m)
Simulation of SHM with spring constant k and mass m
-
lecture_1_mmcd.m
-
View all files
from
MATLAB in Physics - Visualisation
by Matt McDonnell
The first lecture in a series on using MATLABĀ® in undergraduate physics courses.
|
| pendulumDataSimulated(x0, pendulumLength, noiseFactor, outFileName)
|
function pendulumDataSimulated(x0, pendulumLength, noiseFactor, outFileName)
% Generate simulated pendulum data and write this to an Excel spreadsheet.
% Copyright 2008-2009 The MathWorks, Inc.
% $Revision: 35 $ $Date: 2009-05-29 15:27:34 +0100 (Fri, 29 May 2009) $
if nargin<4
outFileName = 'pendulumData.xls';
end
% Define the acceleration due to gravity.
g = 9.81; % m/s
% Determine the natural frequency of the pendulum (this is only accurate in
% the small angle regime, as we will see later).
% This is used here as a scaling factor for the noise added to the measured
% angular velocity of the pendulum.
omega0 = sqrt(g/pendulumLength);
% Simulate the pendulum motion
res = pendulumSimulation(x0,g,pendulumLength);
% Add noise to position and velocity
positionNoise = randn(size(res.Position))*noiseFactor*x0;
velocityNoise = randn(size(res.Position))*noiseFactor*x0*omega0;
% Include this noise into the position and velocity
res.Position = res.Position + positionNoise;
res.Velocity = res.Velocity + velocityNoise;
% Format the data for writing to the Excel spreadsheet.
colHeadings = {'Time', 'Position', 'Velocity'};
dataArray = [res.Time res.Position res.Velocity];
% Create the cell array to write to the Excel file by combining the column
% headings and the numeric simulation results. To do this we need to
% convert the array of numeric data to a cell array using num2cell. Use
% cell2mat to convert a cell array of numbers back to a matrix.
dataArray = [colHeadings; num2cell(dataArray)];
% Save the data
xlswrite(outFileName,dataArray);
|
|
Contact us at files@mathworks.com