1 A Core Course on Modeling Examples street lanterns planets and gravity Week 4 – The Function of Functions.

Slides:



Advertisements
Similar presentations
A core Course on Modeling Introduction to Modeling 0LAB0 0LBB0 0LCB0 0LDB0 S.20.
Advertisements

The Force and Related Concepts.
1 A Core Course on Modeling ACCEL (continued) a 4 categories model dominance and Pareto optimality strength algorithm Examples Week 5 – Roles of Quantities.
Rolling, Torque, and Angular Momentum Rolling: Translation and Rotation Friction and Rolling Yo-yo Torque: A Cross Product Angular Momentum Newton’s Second.
Today’s Lectures: The Laws of Gravity Speed, velocity, acceleration, force Mass, momentum and inertia Newton’s three laws of motion The Force of Gravity.
Computational Methods for Management and Economics Carla Gomes Module 4 Displaying and Solving LP Models on a Spreadsheet.
Chapter 7 Kinetic energy and work Key contents Work and kinetic energy Work done by gravity, springs and a variable force Power.
1 Tutorial Reminder Please download the tutorial from the course web page and try them out Tutorial class will be conducted on 12 DEC 03 (Friday) Submit.
Physics 2011 Chapter 2: Straight Line Motion. Motion: Displacement along a coordinate axis (movement from point A to B) Displacement occurs during some.
6. Work, Energy, and Power. The Dot Product 3 where  is the angle between the vectors and A and B are their magnitudes. The dot product is the scalar.
ELECTRICITY & MAGNETISM (Fall 2011) LECTURE # 4 BY MOEEN GHIYAS.
What about this??? Which one is false?. Aim & Throw where????
Forces Continued Terms that you need to know. Forces Continued In most cases, an object has multiple forces working on it (e.g. gravity, normal, friction)
World Of Science By Ryan Schoenthaler. World of Science Science is a very broad and in-depth subject with lots of different branches like Newton's laws,
Vibrations and Waves AP Physics Lecture Notes m Vibrations and Waves.
Newton believed that every object ___attracts_____ every other object. The force of the attraction depends on the __mass___ and _distance__ of the two.
A core Course on Modeling Introduction to Modeling 0LAB0 0LBB0 0LCB0 0LDB0 P.12.
 Force Due to Gravity. What’s the difference between Mass and Weight?  Mass (m) is the amount of material an object is made from. Also, mass is the.
Physics 1202: Lecture 7 Today’s Agenda Announcements: –Lectures posted on: –HW assignments, solutions.
Physics.
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
Rotational Kinetic Energy An object rotating about some axis with an angular speed, , has rotational kinetic energy even though it may not have.
Definitions ! Forces and Motion. Acceleration ! Acceleration is the rate of change of velocity, with respect to time. Velocity ! Velocity is the rate.
Simple Harmonic Motion: SHM
“If there is one- they have to come (or go)!” Electrostatic Force Field.
Kinematics The study of motion of an object without regard to the causes of the motion. 1. Linear (only along a straight line along a single axis). 2.
Acceleration, Weight and Mass. Weight Near the surface of the Earth, the pull of gravity on a body is practically constant and every falling body acquires.
1© Manhattan Press (H.K.) Ltd. Inertial mass and its measurement Gravitational mass Gravitational mass 3.4 Inertial mass and gravitational mass.
FORCES OF MOTION Georgia Shared Resources. STANDARDS.
Work, Energy and Power Ms Houts AP Physics C Chapters 7 & 8.
Vectors and scalars. weight and mass We have seen that weight is a force that results from the attraction of a mass towards another mass (eg the Earth).
Motion & Forces Vocabulary
The 3 laws of Motion What is motion anyway? Motion is a change in position, measured by distance and time.
Chapter 5 Matter In Motion Section 4 – Gravity: A Force of Attraction pp
IB Assessment Statements Topic 9.2, Gravitational Field, Potential and Energy Define gravitational potential and gravitational potential energy.
Unit 4 Lesson 2 Balanced and Unbalanced Forces
Newton’s 1 st Law: More Practice.
What’s the difference? MASS AND WEIGHT. MASS The quantity of matter in an object Always constant Can never be zero Measured with a balance Unit: grams.
ICP “Work, Energy and Momentum”. Core Content l SC-HS l Students will: select or construct accurate and appropriate representations for motion (visual,
Celestial Mechanics I Introduction Kepler’s Laws.
Chapter 10 Lecture 18: Rotation of a Rigid Object about a Fixed Axis: II.
Work W-E Theorem Pt. 1 1 Newton’s Second Law in Terms of Work Conservation of Kinetic Energy Work-Energy Theorem Work-Energy Diagram.
Electrostatics #4 Energy and Electricity Read and Note Pgs Start HW #5.
Centripetal force Acceleration Mass Contact force momentum
Apply Newton’s First Law to the following illustration.
WHAT IS POSITION?. WHAT IS POSITION? WHAT IS POSITION? LOCATION RELATIVE TO A REFERENCE POINT (FRAME OF REFERENCE)
Systems of Particles.
KINETIC ENERGY AND WORK
Physics: Forces and Newton’s Laws
Object at rest stays at rest,
How to calculate a dot product
Motion.
Physical Science Chapter 12 Section 2
Mass vs. Weight.
Pythagoras.
Chapter 2 Motion.
Find the velocity of a particle with the given position function
Unit 4 Lesson 2 Balanced and Unbalanced Forces
Gravitational Fields Pg
Chapter 13 Gravitation In this chapter we will explore the following topics: -Newton’s law of gravitation that describes the attractive.
What is Motion? Motion: A change in position of an object compared to a reference point Motion can be measured in the following ways:
Chapter 13 Gravitation In this chapter we will explore the following topics: -Newton’s law of gravitation, which describes the attractive force between.
2-4 Acceleration Acceleration is the rate of change of velocity.
Forces.
Work.
Physics: Force, and Motion
Work.
Balanced and unbalanced forces
Momentum and Impulse Lesson 1.
Chapter 2 Forces.
Presentation transcript:

1 A Core Course on Modeling Examples street lanterns planets and gravity Week 4 – The Function of Functions

2 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns image:

3 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns Purpose: how much energy is needed to illuminate road intensity everywhere is between acceptable borders Interesting quantities: totPower maxInt minInt

4 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns Purpose: how much energy is needed to illuminate road intensity everywhere is between acceptable borders Interesting quantities: totPower maxInt minInt  simple: totPower = nLanterns * p  not so simple …

5 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns j i (i,j) dL h roadLength roadWidth lW

6 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns j i dL h roadWidth lW lfG: aggregation of slices slice: aggregation of cells (i=const) cell: receives light from all lanterns roadLength

7 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns lfG: aggregation of slices slice: aggregation of cells (i=const) cell: receives light from all lanterns maxInt=#(i,slices, maxIntensityInSlice(i), max) maxIntensityInSlice(i)=#(j,cellsInSlice(i),cellInt(i,j),max) cellInt(i,j)=lfG(i,j) =lfG[i][j]

8 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns lfG: aggregation of slices slice: aggregation of cells (i=const) cell: receives light from all lanterns maxInt=#(i,slices,#(j,cellsInSlice(i),cellInt(i,j),max),max) maxIntensityInSlice(i)=#(j,cellsInSlice(i),cellInt(i,j),max) cellInt(i,j)=lfG(i,j) =lfG[i][j]

9 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns lfG: aggregation of slices slice: aggregation of cells (i=const) cell: receives light from all lanterns maxInt=#(i,slices,#(j,cellsInSlice(i),lfG[i][j], max),max) maxIntensityInSlice(i)=#(j,cellsInSlice(i),cellInt(i,j),max) cellInt(i,j)=lfG(i,j) =lfG[i][j]

10 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns lfG: aggregation of slices slice: aggregation of cells (i=const) cell: receives light from all lanterns maxInt=#(i,slices,#(j,cellsInSlice(i),lfG[i][j], max),max) slices: lfG consists of slices; vDom('domain') gives the sequence of indices of an aggregation e.g., vDom(['a','b','c','d'])=[0,1,2,3], vDom(['x':17,'y':1])=['x','y'] so: slices = vDom(lfG), and cellsInSlice(i)=vDom(lfG[i])

11 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns lfG: aggregation of slices slice: aggregation of cells (i=const) cell: receives light from all lanterns maxInt=#(i,vDom(lfG),#(j,cellsInSlice(i),lfG[i][j], max),max) slices: lfG consists of slices; vDom('domain') gives the sequence of indices of an aggregation e.g., vDom(['a','b','c','d'])=[0,1,2,3], vDom(['x':17,'y':1])=['x','y'] so: slices = vDom(lfG), and cellsInSlice(i)=vDom(lfG[i])

12 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns lfG: aggregation of slices slice: aggregation of cells (i=const) cell: receives light from all lanterns maxInt=#(i,vDom(lfG),#(j,vDom(lfG[i]), lfG[i][j], max),max) slices: lfG consists of slices; vDom('domain') gives the sequence of indices of an aggregation e.g., vDom(['a','b','c','d'])=[0,1,2,3], vDom(['x':17,'y':1])=['x','y'] so: slices = vDom(lfG) and cellsInSlice(i)=vDom(lfG[i])

13 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns totPow=p*nLanterns maxInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],max),max) minInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],min),min) To be done: definition of lfG definition of p definition of nLanterns

lfG: aggregation of slices slice: aggregation of cells (i=const) cell: receives light from all lanterns Defining lfG : lfG=#(i,slices,lumSlice(i),vAppend) E.g., vAppend([10,20,30],40)=[10,20,30,40] E.g., vAppend(vAppend([],[40,50]),[60,70])=[[40,50],[60,70]] so: lfG=[lumSlice(0),lumSlice(1),lumSlice(2),…] 14 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns j i lumSlice(i) is a function that produces the i-th luminated slice

15 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns totPow=p*nLanterns maxInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],max),max) minInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],min),min) lfG=#(i,vSeq(0,roadWidth),lumOneSlice(i),vAppend) To be done: definition of p definition of nLanterns definition of lumOneSlice() definition of roadWidth

16 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns j i lumAll(i,j) is a function that produces the illumination of cell (i,j), due to 'all' lanterns lfG: aggregation of slices slice: aggregation of cells (i=const) cell: receives light from all lanterns Defining lumSlice(i) : lumSlice(i)=#(j,cellsPerSlice,lumAll(i,j),vAppend)

17 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns totPow=p*nLanterns maxInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],max),max) minInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],min),min) lfG=#(i,vSeq(0,roadWidth),lumOneSlice(i),vAppend) lumOneSlice(w)=#(l,vSeq(0,roadLength),lumAllLant(w,l),vAppend) To be done: definition of p definition of nLanterns definition of lumAllLant() definition of roadWidth, roadLength

18 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns lfG: aggregation of slices slice: aggregation of cells (i=const) cell: receives light from all lanterns Defining lumAll(w,l) : lumAll(w,l)=#(n,allContributingLanterns,lum(w,l,n),add) lum(w,l,n) is a function that produces the illumination of cell (i,j)=(w,l), due to lantern nr. n

19 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns totPow=p*nLanterns maxInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],max),max) minInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],min),min) lfG=#(i,vSeq(0,roadWidth),lumOneSlice(i),vAppend) lumOneSlice(w)=#(l,vSeq(0,roadLength),lumAllLant(w,l),vAppend) lumAllLant(w,l)=#(n,vSeq(-1,nLanterns),lum(w,l,n),add) To be done: definition of p definition of nLanterns definition of lum() definition of roadWidth, roadLength, nLanterns

20 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns lfG: aggregation of slices slice: aggregation of cells (i=const) cell: receives light from all lanterns Defining lum(w,l,n): lum(w,l,n)=p/(h*h+pow(abs(l-n*dL),2)+pow(abs(w-lW),2)) h l - n dL w - lW image:

21 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns totPow=p*nLanterns maxInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],max),max) minInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],min),min) lfG=#(i,vSeq(0,roadWidth),lumOneSlice(i),vAppend) lumOneSlice(w)=#(l,vSeq(0,roadLength),lumAllLant(w,l),vAppend) lumAllLant(w,l)=#(n,vSeq(-1,nLanterns),lum(w,l,n),add) lum(w,l,n)=p/(h*h+pow(abs(l-n*dL),2)+pow(abs(w-Wh),2)) To be done: definition of p definition of nLanterns definition of roadWidth, roadLength, nLanterns, h, dL, Wh

22 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns totPow=p*nLanterns maxInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],max),max) minInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],min),min) lfG=#(i,vSeq(0,roadWidth),lumOneSlice(i),vAppend) lumOneSlice(w)=#(l,vSeq(0,roadLength),lumAllLant(w,l),vAppend) lumAllLant(w,l)=#(n,vSeq(-1,nLanterns),lum(w,l,n),add) lum(w,l,n)=p/(h*h+pow(abs(l-n*dL),2)+pow(abs(w-Wh),2)) p=slider(200,100,2000) nLanterns=1+roadLength/dL dL=slider(25,5,50) h=slider(5,1.5,30) roadLength=40 roadWidth=10 Wh=roadWidth/2 To be done: represent constraints more intuitive output (graphics

23 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns totPow=p*nLanterns maxInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],max),max) minInt=#(i,vDom(lfG),#(j,vDom(lfG[i]),lfG[i][j],min),min) lfG=#(i,vSeq(0,roadWidth),lumOneSlice(i),vAppend) lumOneSlice(w)=#(l,vSeq(0,roadLength),lumAllLant(w,l),vAppend) lumAllLant(w,l)=#(n,vSeq(-1,nLanterns),lum(w,l,n),add) lum(w,l,n)=p/(h*h+pow(abs(l-n*dL),2)+pow(abs(w-Wh),2)) p=slider(200,100,2000) nLanterns=1+roadLength/dL dL=slider(25,5,50) h=slider(5,1.5,30) roadLength=40 roadWidth=10 Wh=roadWidth/2 a=descartes([[image:[scaleX:2,scaleY:2,mapR:lfG,mapG:lfG,mapB:cons]]]) maxP=150 minP=10 cons=if(lfG maxP,255,128))

24 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity

25 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns Purpose: analyse the motions of planets Interesting quantities: for each planet, its location r = [x:xlocation,y:ylocation] as it develops over time

26 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) r = r{1} + v * dt if time > 1 take dt = 1 for simplicity – although this is dimensionally wrong! = initial locations if time  1 So r=[[x:..,y: …], [x:..,y: …], [x:..,y: …], …] and v=[[x:..,y: …], [x:..,y: …], [x:..,y' …], …]

27 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) To do: *define v: a vector of velocities (one for each planet), each velocity being a vector

28 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) v = v{1} + a * dt if time > 1 take dt = 1 for simplicity – although this is dimensionally wrong! = initial velocities if time  1 So v=[[x:..,y: …], [x:..,y: …], [x:..,y: …], …] and a=[[x:..,y: …], [x:..,y: …], [x:..,y: …], …]

29 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) To do: *define a: a vector of accelerations (one for each planet), each acceleration being a vector

30 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) a=cond(time>1,f/m,0) f = ma, so a = f/m Since a is a vector, f and m must be vectors with same amount of elements. Every element of F is a [x: …, y: …] vector; every element of m is a number, so every element of a is a [ x: …, y: …] vector.

31 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) a=cond(time>1,f/m,0) To do: *define f: a vector of forces (one for each planet), each force being a vector

32 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) m a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) To do: *define forceOnOnePlanet() (=the force excerted by all planets in the form of a vector of forces: one force for each of the planets; every force itself is also a vector) Forces (=vectors [x: …, y: …] are appended, i.e. combined into a vector-of-vectors: [[x: …, y: …], [x:..., y: …], [x: …,y: …], …]

33 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) m a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) To do: *define newton (function calculating the force from one planet onto another planet) Condition i != j : planets don't attract themselves. Mapping: [a,b]+c=[a+c,b+c], hence if(i!=j,newton(i,j),0) instead of if(i!=j,newton(i,j),[x:0,y:0]))

34 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) m a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) Gravity force: F ij = g m i m j / ||r i - r j || 2, directed along r i – r j. So: F ij = g m i m j (r i – r j ) / ||r i – r j || 3 mimi mjmj

35 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) m a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) newton(i,j)=g*m[i]*m[j]*distVec(i,j)/(pow( vNormEuclid (distVec(i,j)),3)) To do: *define vNormEuclid *define distVec

36 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) m a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) m distVec newton(i,j)=g*m[i]*m[j]*distVec(i,j)/(pow( vNormEuclid (distVec(i,j)),3)) built-in function: vNormEuclid(a)=  i a i 2

37 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) m a=cond(time>1,f/m,0) pRange f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) m distVec newton(i,j)=g*m[i]*m[j]*distVec(i,j)/(pow( vNormEuclid (distVec(i,j)),3)) To do: *define distVec() (a function, computing the difference between two vectors, returning the difference vector)

38 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) newton(i,j)=g*m[i]*m[j]*distVec(i,j)/(pow( vNormEuclid (distVec(i,j)),3)) distVec(i,j)=r{1}[j]-r{1}[i]

39 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) m a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) m newton(i,j)=g*m[i]*m[j]*distVec(i,j)/(pow( vNormEuclid (distVec(i,j)),3)) distVec(i,j)=r{1}[j]-r{1}[i] To do: *define m (a vector, containing the masses of the planets)

40 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) newton(i,j)=g*m[i]*m[j]*distVec(i,j)/(pow( vNormEuclid (distVec(i,j)),3)) distVec(i,j)=r{1}[j]-r{1}[i] m=[80,2,2,2,2,2,2]

41 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) a=cond(time>1,f/m,0) pRange f=#(i,pRange,forceOnOnePlanet(i),vAppend) pRange forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) newton(i,j)=g*m[i]*m[j]*distVec(i,j)/(pow( vNormEuclid (distVec(i,j)),3)) distVec(i,j)=r{1}[j]-r{1}[i] m=[80,2,2,2,2,2,2] To do: *define pRange (set of numbers, being the indices of the planets)

42 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) newton(i,j)=g*m[i]*m[j]*distVec(i,j)/(pow( vNormEuclid (distVec(i,j)),3)) distVec(i,j)=r{1}[j]-r{1}[i] m=[80,2,2,2,2,2,2] pRange=vSeq(0,7) To do: *define g (gravity)

43 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) newton(i,j)=g*m[i]*m[j]*distVec(i,j)/(pow( vNormEuclid (distVec(i,j)),3)) distVec(i,j)=r{1}[j]-r{1}[i] m=[80,2,2,2,2,2,2] pRange=vSeq(0,7) g=slider(0.002,0,0.01)

44 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity time r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) time v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) time a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) newton(i,j)=g*m[i]*m[j]*distVec(i,j)/(pow( vNormEuclid (distVec(i,j)),3)) distVec(i,j)=r{1}[j]-r{1}[i] m=[80,2,2,2,2,2,2] pRange=vSeq(0,7) g=slider(0.002,0,0.01) To do: time * time: number, increasing one every re-calculation

45 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) newton(i,j)=g*m[i]*m[j]*distVec(i,j)/(pow( vNormEuclid (distVec(i,j)),3)) distVec(i,j)=r{1}[j]-r{1}[i] m=[80,2,2,2,2,2,2] pRange=vSeq(0,7) g=slider(0.002,0,0.01) but time=if(!but,time{1}+1,0) To do: but * but: boolean, being true when user clicks button

46 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) newton(i,j)=g*m[i]*m[j]*distVec(i,j)/(pow( vNormEuclid (distVec(i,j)),3)) distVec(i,j)=r{1}[j]-r{1}[i] m=[80,2,2,2,2,2,2] pRange=vSeq(0,7) g=slider(0.002,0,0.01) time=if(!but,time{1}+1,0) but=button() To do: * nicer visuals (otherwise we see just varying numbers)

47 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity r=cond(time>1,r{1}+v,[[x:0,y:0], [x:15,y:0],[x:7,y:10],[x:-7,y:10],[x:-15,y:0],[x:-7,y:-10], [x:7,y:-10]]) v=cond(time>1,v{1}+a,[[x:0,y:0], [x:0,y:0.1],[x:-0.05,y:0.03],[x:-0.05,y:-0.03],[x:0,y:-0.1],[x:0.05,y:-0.03], [x:0.05,y:0.03]]) a=cond(time>1,f/m,0) f=#(i,pRange,forceOnOnePlanet(i),vAppend) forceOnOnePlanet(i)=#(j,pRange,if(i!=j,newton(i,j),0),add) newton(i,j)=g*m[i]*m[j]*distVec(i,j)/(pow( vNormEuclid (distVec(i,j)),3)) distVec(i,j)=r{1}[j]-r{1}[i] m=[80,2,2,2,2,2,2] pRange=vSeq(0,7) g=slider(0.002,0,0.01) time=if(!but,time{1}+1,0) but=button() plotResult=descartes([[locations:[tagy:- 8,fill: 'interior',data:#(i,pRange,[x:50+r[i].x,y:50+r[i].y,rad:2.5* pow(m[i],0.33),tag:names[i],pointSize:pointSizes[i]],vAppend)]]]) names=['sun','1','2','3','4','5','6'] pointSizes=[5,3,3,3,3,3,3,3]