1. Engineering
  2. Computer Science
  3. in matlab...

Question: in matlab...

Question details

18. Modify the pendul program so that it plots w(t) versus vuy, tnat Is, a pnase space plot. Instead of running for a fixed number of steps, have your program halt the calculation when the pendulum completes one period. Using the Verlet method, plot the data for initial angles of 10, 45, 90, 120, and 170°. Notice how the shape of the phase space orbit changes as a function of the initial angle. [Computer) 19. Consider a particle of mass m moving along the z-axis under the influence of the force where Fo is a constant, (a) Using the analysis presented in this section, show that the period is position. Pencil] (b) Write a program to compute the trajectory of the particle and confirm the result from part (a). [Computer V/2mar, Fo, where xm įs the maximurn value for the particles e pendul program computes the period in a rather crude fashion Improve In MATLAB
Listing 2A.2 Program pendul. Computes the time evolution of a simple pendulum using the Euler or Verlet methods % pendul -Program to compute the motion of a simple pendulum % using the Euler or Verlet method clear all; help pendul % clear the memory and print header
2 ODES E BASIC METH 60 %* Select the numerical method to NumericalMethod -menu Choose a use: Euler or Verlet Euler, Verlet); Set initial position and velocity of pendulu thetao input (Enter initial angle (in degrees): theta-theta0*pi/180; % Convert angle to radians % set the initial velocity omega - o %* Set the physical constants and other variables g over L 1 time 0 irev 0; tau = input(Enter time step: ,) ; % The constant g/L % Initial tine % Used to count number of reversals Take one backvard step to start Verlet accel=-g-over-L*sin(theta); % Gravitational acceleration theta.old - theta - omega*tau 0.5+tau2.accel; %* Loop over desired number of steps with given tine step % and nunerical nethod nstep - input ( Enter number of time steps:; for istep-1:nstep %* Record angle and tie for plotting t-plot (istep) - time; th-plot(istep) . thetar 180/pi; % Convert angle to degrees tine time + tau ; x-compute new position and velocity using Euler or Verlet sethod accel.-g-over-L*sin(theta); if NumericalMethod1) % Gravitational acceler ation theta old theta; theta theta+ tau onega; omega onega+ tau accel; % save previous angle % Euler method else theta.neu -2 theta- theta old tau 2 accel; theta old theta; theta theta-ner; % Verlet method end Test if the pendulum has passed through theta x if yes, use tine to estinate period if ( theta-theta-old < 0 ) % Test position for sign fprintf(*Turning point at time t-%f la,,time); -0 change
APPENDIX B: C++ LISTINGS 61 if( irev0) % If this is the first change, % just record the time time_old time; else period(irev) 2* (time time_old); time_old time; end % increment the number of reversals end end %* Estimate period of oscillation, including error bar AvePeriod mean (period); ErrorBar std(period)/sqrt (irev); fprintf (Average period %g +/-%gin, AvePeriod , ErrorBar); %* Graph the oscillations as theta versus time clf figure(gcf); plot (t_plot,th_plot,+); xlabel (Time); ylabel (Itheta (degrees)); % Clear and forward figure window
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution