Download presentation
Presentation is loading. Please wait.
Published bySusan Bell Modified over 9 years ago
1
1 A Core Course on Modeling Examples street lanterns planets and gravity Week 4 – The Function of Functions
2
2 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns image: http://www.westberks.gov.uk/index.aspx?articleid=3785
3
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
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
5 A Core Course on Modeling Week 4 – The Function of Functions Street Lanterns j i (i,j) dL h roadLength roadWidth lW
6
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
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
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
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
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
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
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
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
14
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
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
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
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
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
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
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: http://www.ph.unimelb.edu.au/~ddolce/
21
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
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
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
24 A Core Course on Modeling Week 4 – The Function of Functions Planets and Gravity http://www.opencourse.info/astronomy/introduction/05.motion_planets/
25
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.