INTRODUCTION TO MATLAB

Slides:



Advertisements
Similar presentations
Lab5 (Signal & System) Instructor: Anan Osothsilp Date: 20 Feb 07 Due Date 09 March 07.
Advertisements

Kinetic energy. Energy Energy is usually defined as the capacity to do work. One type of energy is kinetic energy.
1 Oscillations oscillations_02 CP Ch 14 How can you determine the mass of a single E-coli bacterium or a DNA molecule ? CP458 Time variations that repeat.
Chapter 10: Rotation. Rotational Variables Radian Measure Angular Displacement Angular Velocity Angular Acceleration.
Chapter Ten Oscillatory Motion. When a block attached to a spring is set into motion, its position is a periodic function of time. When we considered.
Oscillations x(t)=x m cos(  t+  ) v(t)=-  x m sin (  t+  ) v m =  x m ‘amplitude’ shifted by T/4 (90 0 ) a(t)=-  2 x m cos(  t+  ) a m =  2 x.
Phy 212: General Physics II Chapter 15: Oscillations Lecture Notes.
The simple pendulum Energy approach q T m mg PH421:Oscillations F09
Simple Harmonic Motion
Springs And pendula, and energy. Spring Constants SpringkUnits Small Spring Long Spring Medium spring 2 in series 2 in parallel 3 in series 3 in parallel.
Problmes-1.
Physics 111: Elementary Mechanics – Lecture 9 Carsten Denker NJIT Physics Department Center for Solar–Terrestrial Research.
10/22/2012PHY 113 A Fall Lecture 211 PHY 113 A General Physics I 9-9:50 AM MWF Olin 101 Plan for Lecture 21: Chapter 15 – Simple harmonic motion.
Mechanical Energy and Simple Harmonic Oscillator 8.01 Week 09D
Chapter 15 Oscillatory Motion.
Springs And pendula, and energy. Harmonic Motion Pendula and springs are examples of things that go through simple harmonic motion. Simple harmonic motion.
Unit 6 Lesson 1 Simple Harmonic Motion SHM
Motion of a mass at the end of a spring Differential equation for simple harmonic oscillation Amplitude, period, frequency and angular frequency Energetics.
Give the expression for the velocity of an object rolling down an incline without slipping in terms of h (height), M(mass), g, I (Moment of inertia) and.
Simple Harmonic Motion Chapter 12 Section 1. Periodic Motion A repeated motion is what describes Periodic Motion Examples:  Swinging on a playground.
11 rotation The rotational variables Relating the linear and angular variables Kinetic energy of rotation and rotational inertia Torque, Newton’s second.
Projectile Motion Projectiles launched at an angle.
10/3 Energy Intro  Text: Chapter 6 Energy  HW 10/3 “2nd Law vs. Energy” due Monday 10/7  Tomorrow, Potential Energy and Projectile Motion  Exam 2 Thursday,
Rotational Mechanics. Rotary Motion Rotation about internal axis (spinning) Rate of rotation can be constant or variable Use angular variables to describe.
Ch. 13 Oscillations About Equilibrium
Physics 221 Chapter 7 Problem 1... Work for slackers! WORK = Force x Distance W = F. D Units: Nm = J Newton meters = Joules Problem 1 : You push a car.
Periodic Motion Motion that repeats itself over a fixed and reproducible period of time is called periodic motion. The revolution of a planet about its.
Simple Harmonic Motion This type of motion is the most pervasive motion in the universe. All atoms oscillate under harmonic motion. We can model this motion.
Work and Energy. Scalar (Dot) Product When two vectors are multiplied together a scalar is the result:
Work Readings: Chapter 11.
Rotational Dynamics 8.3. Newton’s Second Law of Rotation Net positive torque, counterclockwise acceleration. Net negative torque, clockwise acceleration.
WORK KINETIC ENERGY THEOREM. THE WORK ENERGY THEOREM Up to this point we have learned Kinematics and Newton's Laws. Let 's see what happens when we apply.
 One way to understand SHM is to reconsider the circular motion of a particle and rotational kinematics (The Reference Circle)  The particle travels.
Introductory Video: Simple Harmonic Motion Simple Harmonic Motion.
Simple Harmonic Motion Things that vibrate § 14.1–14.3.
Dynamics. Motion with Regard to Mass Particle Dynamics Mass concentrated in point Newton’s Equation Governs Motion f = M x.
Work Done by a Constant Force The work done by a constant force is defined as the distance moved multiplied by the component of the force in the direction.
1 The law of gravitation can be written in a vector notation (9.1) Although this law applies strictly to particles, it can be also used to real bodies.
Simple Harmonic Motion Waves 14.2 Simple Harmonic motion (SHM ) 14-3 Energy in the Simple Harmonic Oscillator 14-5 The Simple Pendulum 14-6 The Physical.
Energy of Simple Harmonic Motion
Physics Section 11.1 Apply harmonic motion
Chapter 13: Oscillatory Motion
Simple Harmonic Motion
Definition of a System Energy of a System Momentum of a System
Definition of a System Energy of a System Momentum of a System
Differential Equation of the Mechanical Oscillator
Elasticity and Oscillations
Applications of SHM and Energy
Computer Application in Engineering Design
Mechanics Review – SEMESTER 1
Harmonic Motion (III) Physics 1D03 - Lecture 33.
Oscillations © 2014 Pearson Education, Inc..
PROJECTILE MOTION.
s= mt+constant where m=Ds/Dt i.e., speed
PhET mass spring applet
Mechanics & Molecular Kinetic Theory
What is Physics?.
Oscillations Readings: Chapter 14.
Numerical Solution/Simulation
A quick heads up on You will be able to derive it soon… Enquiry:
Trebuchet Calculations
Group Work Predict the motion of a mass acted on only by a Hooke’s law spring. Express your prediction as a position-time graph. Explain why you believe.
Differential Equation of the Mechanical Oscillator
What do you think a “launch” looks like?
Chapter Three Review.
SPRING TWO MASSES – CREATING XYZ FILE AND ANIMATION.
Simple Harmonic Motion
Work, Energy, Power.
Ch. 12 Waves pgs
Presentation transcript:

INTRODUCTION TO MATLAB Creating basic scripts

PROJECTILE 1

POWEER! Stupid pig.. Angry Birds®

Newton`s equation wektory

Newton`s equation Dv/dt = a!

Dv/dt=a

Newton`s equation – algorithm we

Newton`s equation – algorithm Nad r wektor

Newton`s equation – algorithm example

Newton`s equation – algorithm example

Projectile in LibreOffice Calc

t: 0 to 3 [s]

t: 0 to 3 [s]

Acceleration in x direction is 0. RADIAN X(t-1) Acceleration in x direction is 0.

PLOT

scatter

Now, let`s try to change initial values of the velocity, Δt and initial angle. What do you observe?

PROJECTILE TASK CALCULATE AND PLOT REAL VALUE OF THE Y COORDINATE. COMPARE IT WITH THE VALUE OF Y CALCULATED WITH NEWTON`S EQUATION.

TO NAME YOUR SERIES FOR PLOT

PROJECTILE IN MATLAB– initial values clc clear all v=100; % [m/s] initial value of velocity alpha=pi/4; % [rad] initial value of angle g=9.81; % [m/(s^2)] gravity constant dt=0.1; %[s] single time step In MATLAB you are not supposed to define type of variable

PROJECTILE – initial values %position x(1)=0; %[m] y(1)=0; %[m] % initial values of vx and vy vx(1)=v*cos(alpha); %[m/s] vy(1)=v*sin(alpha); %[m/s] Number one in brackets mean, that x variable is list (contains many values), and now first value is being defined

PROJECTILE – initial values %position x(1)=0; %[m] y(1)=0; %[m] % initial values of vx and vy vx(1)=v*cos(alpha);%[m/s] vy(1)=v*sin(alpha);%[m/s] Number one in brackets mean, that x variable is list (contains many values), and now first value is being defined

PROJECTILE - loop for s=2:144 % for each s from 2 to 144. Started from 2, because 1 is initial value (already defined) vx(s)=vx(s-1); vy(s)=vy(s-1)-g*dt; %new vy = previous vy - gravity in delta t x(s)=x(s-1)+vx(s)*dt; %new position y(s)=y(s-1)+vy(s)*dt; end Loop starts with for (and condition), then repeatable intructions - each after indent, and 'end'. New vx (in point s) = vx in previous point (s-1)

BUT SOME EXAMPLES FIRST PROJECTILE - loop BUT SOME EXAMPLES FIRST for s=2:144 % for each s from 2 to 144. Started from 2, because 1 is initial value (already defined) vx(s)=vx(s-1); vy(s)=vy(s-1)-g*dt; %new vy = previous vy - gravity in delta t x(s)=x(s-1)+vx(s)*dt; %new position y(s)=y(s-1)+vy(s)*dt; end Loop starts with for (and condition), then repeatable intructions - each after indent, and 'end'. New vx (in point s) = vx in previous point (s-1)

PROJECTILE – loop example for s=2 vx(2)=vx(2-1); vy(2)=vy(2-1)-g*dt; %new vy = previous vy - gravity * timestep x(2)=x(2-1)+vx(2)*dt; %new position y(2)=y(2-1)+vy(2)*dt; end

PROJECTILE – loop example for s=2 vx(2)=vx(2-1); vy(2)=vy(2-1)-g*dt; %new vy = previous vy - gravity * timestep x(2)=x(2-1)+vx(2)*dt; %new position y(2)=y(2-1)+vy(2)*dt; end

PROJECTILE – loop example for s=3 vx(3)=vx(3-1); vy(3)=vy(3-1)-g*dt; %new vy = previous vy - gravity * timestep x(3)=x(3-1)+vx(3)*dt; %new position y(3)=y(3-1)+vy(3)*dt; end

PROJECTILE – loop example for s=3 vx(3)=vx(3-1); vy(3)=vy(3-1)-g*dt; %new vy = previous vy - gravity * timestep x(3)=x(3-1)+vx(3)*dt; %new position y(3)=y(3-1)+vy(3)*dt; end

PROJECTILE - loop for s=2:144 % for each s from 2 to 144. Started from 2, because 1 is initial value (already defined) vx(s)=vx(s-1); vy(s)=vy(s-1)-g*dt; %new vy = previous vy - gravity in delta t x(s)=x(s-1)+vx(s)*dt; %new position y(s)=y(s-1)+vy(s)*dt; end Loop starts with for (and condition), then repeatable instructions - each after indent, and 'end'. New vx (in point s) = vx in previous point (s-1)

PROJECTILE - plot plot (x,y) xlabel('distance') ylabel('height') Plot will be opened in new window while executing script Plot(x-axis values list, y-axis values list) Every text in code is required to be in quotes

PROJECTILE - results

CHANGE: TO RUN CALCULATION plot (x,y) xlabel('distance') ylabel('height') TO plot1(x,y,dt,vx,vy) RUN CALCULATION

IF YOU PLOT ALL ENERGIES OVER TIME WHAT DO YOU OBSERVE? PROJECTILE TASK ADD TO THE LOOP AND CALCULATE POTENTIAL ENERGY, KINETIC ENERGY AND TOTAL ENERGY, THEN PLOT THEM. IF YOU PLOT ALL ENERGIES OVER TIME WHAT DO YOU OBSERVE? Masa!!!!!!!!!!!!!!!!!!!!!!

IF YOU PLOT THESE ENERGIES OVER TIME WHAT DO YOU OBSERVE? PROJECTILE TASK ADD TO THE LOOP AND CALCULATE POTENTIAL ENERGY, KINETIC ENERGY AND TOTAL ENERGY, THEN PLOT THEM. IF YOU PLOT THESE ENERGIES OVER TIME WHAT DO YOU OBSERVE? Remember to add the initial values of the energies before the loop…

PROJECTILE – initial value of energy %energy - initial values ep(1)=g*y(1)*m; %potential energy ek=(vx(1)^2+vy(1)^2)*m/2; %kinetic energy ec(1)=ek(1)+ep(1); %total energy

PROJECTILE– energies added to loop for s=2:144 vx(s)=vx(s-1); vy(s)=vy(s-1)-g*dt; x(s)=x(s-1)+vx(s)*dt; y(s)=y(s-1)+vy(s)*dt; ep(s)=g*y(s)*m; ek(s)=(vx(s)^2+vy(s)^2)*m/2; ec(s)=ep(s)+ek(s); t(s)=t(s-1)+dt; end

PROJECTILE - plot plot (t,ec) xlabel('time') ylabel('energy') legend ('total energy','Location', 'NorthEast') % plot of each energy plot (t,ec,t,ek,t,ep) legend ('total energy','kinetic energy','potential energy','Location', 'NorthEast')

Result!

NOW CHANGE VALUE OF STEPS TO 2:150 Result! NOW CHANGE VALUE OF STEPS TO 2:150

PROJECTILE - results

PROJECTILE - results

SPRING One mass

L0

L0 x

1 2 Equilibrium position 5 3 s 4 Attachment point

SPRING – initial values clc clear all %initial values x=4; %extention k=0.1; %spring constant m=1; %mass dt=0.1; % time step

SPRING – initial values t(1)=0; %time x(1)=x; %position v(1)=0; %velocity

SPRING - loop for i=2:510 v(i)=v(i-1)+(-k*x(i-1)/m)*dt; x(i)=x(i-1)+dt*v(i); t(i)=t(i-1)+dt; end

SPRING - plot plot(t,x) xlabel('time') legend('position','Location','NorthEast')

SPRING - results

1 2 Equilibrium position 5 3 s 4 Attachement point

RUN CALCULATION ADD ENERGIES (to the loop) THEN ANIMATION ep(i)=k*x(i)^2/2; ek(i)=m*v(i)^2/2; ec=ep+ek; THEN ANIMATION plot3(x,dt,v,t,ep,ek,ec) RUN CALCULATION Kulka i wykres sinusoidy> energie rysowane> nie są zachowane bo dt jest małe > jak polepszyć??? > zadanie z kulką > feature 3 subplot(2,2,4) xlim([-limits(6) limits(6)]) ylim([-limits(7) limits(7)]) xlabel('position (x)') ylabel('velocity (v)') grid hold on Do loop subplot(2,2,4); trace4=plot(y(k),v(k),'y:o',... 'MarkerFaceColor',[.0 k/numel(y) .7058],... 'Color',[.0 k/numel(y) .7058],... 'LineWidth',3.5);

ARE THE CALCULATIONS CORRECT? What about the total energy? ARE THE CALCULATIONS CORRECT?

ENERGY CONSERVATION LAW Ep Ek

ENERGY CONSERVATION LAW

ENERGY CONSERVATION LAW Looks familiar?

ENERGY CONSERVATION LAW Looks familiar?

ENERGY CONSERVATION LAW ADD after your loop: v=v*sqrt(m/k); PLOT: plot(x,v)

RESULT A

CHANGE: plot(x,v) TO plot4(v,x,dt) RUN CALCULATION

SPRING Two masses

1 2 L

2 1 L Δx1 L+Δx2

F1= k*Δl F2= -k*Δl 1 2 x1 x2 -0.1 L 0.1 X2-x2= Odwrocic dl

SPRING – initial values clc clear all l=2; m=1; k=3; dt=0.1;

SPRING – initial values x1(1)=-0.5; x2(1)=l+1; t(1)=0;

SPRING - loop

SPRING - plot plot(t,x1,t,x2) xlabel('t') ylabel('x') legend ('x1','x2','Location', 'NorthWest')

SPRING - results

CHANGE: TO RUN CALCULATION plot5(x1,x2,dt,v1,v2,t) plot(t,x1,t,x2) xlabel('t') ylabel('x') legend ('x1','x2','Location', 'NorthWest') TO plot5(x1,x2,dt,v1,v2,t) RUN CALCULATION

IF YOU PLOT ALL ENERGIES OVER TIME WHAT DO YOU OBSERVE? SPRING TASK ADD TO THE LOOP AND CALCULATE POTENTIAL ENERGY, KINETIC ENERGY AND TOTAL ENERGY, THEN PLOT THEM. IF YOU PLOT ALL ENERGIES OVER TIME WHAT DO YOU OBSERVE?

RESULTS

THE PURPOSE! Knowledge and experience = endless possibilieties Creating models of particles, such as chloride and hydrogen. Working only with computer and creating real experiment. cl

Cl2 molecule k = 322.7 N/m – spring constant for chlorine system 𝜇= 𝑚 1 𝑚 2 𝑚 1 + 𝑚 2 =2.903∗ 10 −26 𝑘𝑔 – reduced mass x = 5*10-12 m – typical atomic displacement Two body problem reduced to one body problem by introduction of reduced mass: cl 𝑑 2 𝑥 𝑑 𝑡 2 + k 𝜇 x=0

We can use our program to get… Atomic motion Spectrum Fourier’s transform cl wavenumber 1.678*1013 𝜈 =559.72 𝑐 𝑚 −1 1/1.678*1013

SEE YOU TOMMOROW!