

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Notes; Professor: Parthasarathy; Class: Foundat Physics II; Subject: Physics; University: University of Oregon; Term: Fall 2007;
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!
The general solution x(t) = A sin(ωt - ϕ). The initial x(t=0) = 0, so ϕ = 0. v(t=0) = A ω cos(ωt) = v 0 , so A = v 0 /ω. Therefore the particular solution x(t) = (v 0 /ω) sin(ωt).
Program listing, with “new” lines in bold:
% verletSHO_P7.m % SOLUTION to exercise P7 -- modifying SHO model to have a variable timestep % and also to plot the exact SHO solution % % Raghuveer Parthasarathy % Oct. 5, 2007
clear all close all
x(1) = 0.0; % initial position, meters v(1) = 2.0; % initial velocity, m/s Deltat = input('Enter Deltat (seconds): '); % time increment, s x(2) = x(1) + v(1)*Deltat; %We’ll explicitly write x(1), even though % it’s zero here, in case we ever want to change % our initial conditions. (Otherwise, we might get % confused!) k = 0.1; % Newtons / meter m = 1.0; % kilograms
% for exact solution % General solution x = A sin(wt - phi) % Initial x(t=0) = 0, so phi = 0. v(t=0) = Aw cos(wt)=v0, so A = v0/w ta = 0:0.1:100; % time array, seconds w = sqrt(k/m); % angular freqency (omega), radians / sec xa = (v(1) / w)sin(wta);**
Tfinal = 100.0; % ending time, seconds t = 0:Deltat:Tfinal; % an array of all the time values -- starts at 0 N = length(t); % “length” gives the number of elements in an array for j=3:N; x(j) = 2x(j-1) - x(j-2) + DeltatDeltat(-1.0k/m)x(j-1); v(j-1) = (x(j) - x(j-2))/ (2Deltat); end v(N) = (x(N)-x(N-1))/Deltat; % Why? Because v(N) % is not set by the above For loop figure; plot(t, x, 'ko:'); grid on; xlabel('Time, sec. '); ylabel('x, meters') hold on plot(ta, xa, 'b-');
Output (Δt = 0.5 s). We see that the numerical and analytic solutions are very similar.
Output (Δt =3, 6 s).
We see that for larger Δt, the numerical solution is increasingly incorrect. This is because our algorithm, based on a Taylor expansion of x(t), is an increasingly poor approximation to the true “continuous” x(t).
Mr. K. suggests Δt = 0.0001 seconds. He thinks this is a good idea because, as noted above, smaller Δt yields a better approximation to the true x(t). However, it requires lots of calculation time – to model 100 seconds with Δt = 0.0001 seconds requires 10^6 passes through our for-loop, which may be slow.