Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
red_car_mass := 251.8~0.05 "CAR 1" blue_car_mass := 254.0~0.05 "CAR 2" m1_mass := 252.4~0.05 m2_mass := 254.2~0.05 slopes := [0.0186~0.00015, 0.0213~0.00025, 0.0259~0.00024, 0.0187~0.00069, 0.0225~0.00025] define extract_column(matrix, col) as column := [] for row in matrix loop column | row[col] end loop return column end extract_column define extract_columns(matrices, col) as return ((x) -> extract_column(x, col))`(matrices) end extract_columns define flatten(matrix) as result := [] for set in matrix loop result.extend(set) end loop return result end flatten define sum(x, y) as return x + y end sum define sums(x, y) as return sum`(x, y) end sums print("The standard deviation of our measurements is:", std(slopes)) "=== Elastic data ===" "[beginning_pos, cart2_v_at, cart1_v_after, cart2_v_after]" elastic_collisions_data_massless := [ [1.6, 0.312249, -0.289780, -0.005616], [2.070, 0.343593, -0.323470, -0.002712], [1.94, 0.365498, -0.313415, -0.001286], [1.26, 0.688140, -0.708082, 0.008666], [2.04, 0.205810, -0.186434, -0.011421] ] "[beginning_pos, cart2_v_at, cart1_v_after, cart2_v_after]" elastic_collisions_data_massed := [ [1.3, 0.338302, -0.330059, -0.003630], [0.860, 0.383199, -0.34254, 0.001001], [1.260, 0.260496, -0.256836, -0.006353], [1.270, 0.472937, -0.460785, -0.002867], [1.260, 0.574692, -0.559910, 0.0001650842] ] "[beginning_pos, cart2_v_at, cart1_v_after, cart2_v_after]" elastic_collisions_data_c1m1 := [ [1.26, 0.447398, -0.284034, -0.14181], [1.08, 0.443326, -0.272659, -0.134786], [1.34, 0.435538, -0.266906, -0.146262], [1.4, 0.376664, -0.244017, -0.118208] ] "[beginning_pos, cart2_v_at, cart1_v_after, cart2_v_after]" elastic_collisions_data_c1m2 := [ [1.7, 0.596225, -0.289686, -0.300989], [0.7, 0.59995, -0.278186, -0.267378], [0.68, 0.785811, -0.370249, -0.351386], [1.72, 0.492266, -0.220981, -0.233584] ] "[beginning_pos, cart2_v_at, cart1_v_after, cart2_v_after]" elastic_collisions_data_c2m1 := [ [0.71, 0.302166, -0.41089, 0.089709], [1.640, 0.220673, -0.300117, 0.061775], [0.880, 0.307913, -0.418068, 0.100391], [0.580, 0.35472, -0.446097, 0.117493] ] "[beginning_pos, cart2_v_at, cart1_v_after, cart2_v_after]" elastic_collisions_data_c2m2 := [ [1.32, 0.197016, -0.268901, 0.083176], [1.19, 0.26225, -0.321149, 0.111764], [1.46, 0.229498, -0.303468, 0.094574], [1.33, 0.203483, -0.286996, 0.086106] ] "=== Inelastic data ===" "[beginning_pos, cart2_v_at, cart1_v_after]" inelastic_collisions_data_massless := [ [1.43, 0.392352, -0.196709], [1.35, 0.496739, -0.241296], [1.08, 0.69781, -0.337878], [1.03, 0.489847, -0.239846] ] "[beginning_pos, cart2_v_at, cart1_v_after]" inelastic_collisions_data_c1m1 := [ [0.960, 0.588607, -0.202218], [1.88, 0.407084, -0.14504], [1.14, 0.580273, -0.189352] ] "[beginning_pos, cart2_v_at, cart1_v_after]" inelastic_collisions_data_c1m2 := [ [0.96, 0.851525, -0.132017], [2.28, 0.558863, -0.136012], [2.1, 0.632977, -0.153357] ] "[beginning_pos, cart2_v_at, cart1_v_after]" inelastic_collisions_data_c2m1 := [ [2.08, 0.442954, -0.294568], [2.56, 0.47818, -0.306290], [1.26, 0.460557, -0.315441] ] "[beginning_pos, cart2_v_at, cart1_v_after]" inelastic_collisions_data_c2m2 := [ [1.84, 0.56718, -0.393595], [1.78, 0.413264, -0.31968], [1.74, 0.492195, -0.38198] ] all_data := [ elastic_collisions_data_massless, elastic_collisions_data_c1m1, elastic_collisions_data_c1m2, elastic_collisions_data_c2m1, elastic_collisions_data_c2m2, inelastic_collisions_data_massless, inelastic_collisions_data_c1m1, inelastic_collisions_data_c1m2, inelastic_collisions_data_c2m1, inelastic_collisions_data_c2m2 ] define calc_kinetic(mass, velocity) as return 0.5 * mass * velocity ^ 2 end calc_kinetic define calc_momentum(mass, velocity) as return mass * velocity end calc_momentum define negate_car1v(list) as for row in list loop row[2] := -1 * row[2] end loop end negate_car1v "Since the sensors were in different directions, we needed to negate one of them" "We chose to negate the one pointing towards car 1" negate_car1v`(all_data) from physics_utils.graph import SimpleGraph, show "From the velocities of the carts, calculate the momenta and kinetic energies. Plot the total kinetic energy before the" "collision vs the total kinetic energy after collision. Is kinetic energy conserved (i.e. is the collision 'elastic')?" "What slope would this correspond to? Also, plot the momenta before collision vs momenta after the" "collision. Is momentum conserved?" elastic_datasets := [ elastic_collisions_data_massless, elastic_collisions_data_c1m1, elastic_collisions_data_c1m2, elastic_collisions_data_c2m1, elastic_collisions_data_c2m2 ] elastic_masses_c1 := [ red_car_mass, red_car_mass + m1_mass, red_car_mass + m1_mass + m2_mass, red_car_mass, red_car_mass ] elastic_masses_c2 := [ blue_car_mass, blue_car_mass, blue_car_mass, blue_car_mass + m1_mass, blue_car_mass + m1_mass + m2_mass ] elastic_c1_velocities_after := extract_columns(elastic_datasets, 2) elastic_c2_velocities_before := extract_columns(elastic_datasets, 1) elastic_c2_velocities_after := extract_columns(elastic_datasets, 3) "First, let's calculate the momenta for each dataset:" print() define calc_momenta_on_dataset(mass, velocities) as return ((x) -> calc_momentum(mass, x))`(velocities) end calc_momenta_on_dataset cart1_momenta_after := calc_momentum**(*elastic_masses_c1, **elastic_c1_velocities_after) cart2_momenta_before := calc_momentum**(*elastic_masses_c2, **elastic_c2_velocities_before) cart2_momenta_after := calc_momentum**(*elastic_masses_c2, **elastic_c2_velocities_after) total_momenta_before := cart2_momenta_before total_momenta_after := sums`(cart2_momenta_after, cart1_momenta_after) elastic_total_momenta_before := total_momenta_before elastic_total_momenta_after := total_momenta_after print("Total momenta before:", total_momenta_before) print("Total momenta after:", total_momenta_after) "& graph it:" momenta_graph := SimpleGraph("Momentum before vs after elastic collision") momenta_graph.set_x_axis(flatten(total_momenta_after), "Total momentum after (g m / s)") momenta_graph.set_y_axis(flatten(total_momenta_before), "Total momentum before (g m / s)") momenta_graph.plot_points() momenta_graph.put_labels() line_info := momenta_graph.best_fit(true) print("Line of best fit for elastic momenta graph:", "$y=({})x+{}$".format(line_info[0].latex(false), line_info[1].latex(false))) "Now, let's calculate the kinetic energy:" print() define calc_ke_on_dataset(mass, velocities) as return ((x) -> calc_kinetic(mass, x))`(velocities) end calc_ke_on_dataset cart1_ke_after := calc_ke_on_dataset`(elastic_masses_c1, elastic_c1_velocities_after) cart2_ke_before := calc_ke_on_dataset`(elastic_masses_c2, elastic_c2_velocities_before) cart2_ke_after := calc_ke_on_dataset`(elastic_masses_c2, elastic_c2_velocities_after) total_ke_before := cart2_ke_before total_ke_after := sums`(cart2_ke_after, cart1_ke_after) elastic_total_ke_before := total_ke_before elastic_total_ke_after := total_ke_after print("Total kinetic energy before:", total_ke_before) print("Total kinetic energy after:", total_ke_after) "& graph it:" ke_graph := SimpleGraph("Kinetic energy before vs after elastic collision") ke_graph.set_x_axis(flatten(total_ke_after), "Total kinetic energy after (g m^2 / s^2)") ke_graph.set_y_axis(flatten(total_ke_before), "Total kinetic energy before (g m^2 / s^2)") ke_graph.plot_points() ke_graph.put_labels() line_info := ke_graph.best_fit(true) print("Line of best fit for elastic kinetic graph:", "$y=({})x+{}$".format(line_info[0].latex(false), line_info[1].latex(false))) "Ok now we're doing the stuff for the inelastic collision" "you will find each cart's velocity before the collision, and the velocity of the" "combined system of two carts after collision (because they're stuck together). Once again, compare" "the momenta and kinetic energies before and after the collision. Is this collision elastic? Is kinetic" "energy conserved? Is momentum conserved? If one was not conserved, what happened to it?" inelastic_datasets := [ inelastic_collisions_data_massless, inelastic_collisions_data_c1m1, inelastic_collisions_data_c1m2, inelastic_collisions_data_c2m1, inelastic_collisions_data_c2m2 ] inelastic_masses_c1 := [ red_car_mass, red_car_mass + m1_mass, red_car_mass + m1_mass + m2_mass, red_car_mass, red_car_mass ] inelastic_masses_c2 := [ blue_car_mass, blue_car_mass, blue_car_mass, blue_car_mass + m1_mass, blue_car_mass + m1_mass + m2_mass ] inelastic_c1_velocities_after := extract_columns(inelastic_datasets, 2) inelastic_c2_velocities_before := extract_columns(inelastic_datasets, 1) inelastic_c2_velocities_after := extract_columns(inelastic_datasets, 2) "Let's calculate the momenta:" print() total_momenta_before := calc_momenta_on_dataset`(inelastic_masses_c2, inelastic_c2_velocities_before) total_momenta_after := calc_momenta_on_dataset`(sums(inelastic_masses_c2, inelastic_masses_c1), inelastic_c2_velocities_after) inelastic_total_momenta_before := total_momenta_before inelastic_total_momenta_after := total_momenta_after print("Total momenta before:", total_momenta_before) print("Total momenta after:", total_momenta_after) "& graph it:" momenta_graph := SimpleGraph("Momentum before vs after inelastic collision") momenta_graph.set_x_axis(flatten(total_momenta_after), "Total momentum after (g m / s)") momenta_graph.set_y_axis(flatten(total_momenta_before), "Total momentum before (g m / s)") momenta_graph.plot_points() momenta_graph.put_labels() line_info := momenta_graph.best_fit(true) print("Line of best fit for inelastic momentum graph:", "$y=({})x+{}$".format(line_info[0].latex(false), line_info[1].latex(false))) "Now, let's calculate the kinetic energy:" print() cart1_ke_after := calc_ke_on_dataset`(inelastic_masses_c1, inelastic_c1_velocities_after) cart2_ke_before := calc_ke_on_dataset`(inelastic_masses_c2, inelastic_c2_velocities_before) cart2_ke_after := calc_ke_on_dataset`(inelastic_masses_c2, inelastic_c2_velocities_after) total_ke_before := cart2_ke_before total_ke_after := sums`(cart2_ke_after, cart1_ke_after) inelastic_total_ke_before := total_ke_before inelastic_total_ke_after := total_ke_after print("Total kinetic energy before:", total_ke_before) print("Total kinetic energy after:", total_ke_after) "& graph it:" ke_graph := SimpleGraph("Kinetic energy before vs after inelastic collision") ke_graph.set_x_axis(flatten(total_ke_after), "Total kinetic energy after (g m^2 / s^2)") ke_graph.set_y_axis(flatten(total_ke_before), "Total kinetic energy before (g m^2 / s^2)") ke_graph.plot_points() ke_graph.put_labels() "Finally, let's see our graphs:" show() print() print("Now, for our tables") print() from physics_utils.table import Table2D trial_num := [0] define make_row(m1, m2, run) as trial_num[0] := trial_num[0] + 1 return [trial_num[0].__int__(), m1, m2, run[1], run[2], run[3]] end make_row table_data := flatten(((m1, m2, runs) -> ((run) -> make_row(m1, m2, run))`(runs))`(elastic_masses_c1, elastic_masses_c2, elastic_datasets)) elastic_collision_table := Table2D() elastic_collision_table.set_labels(["$m_1$", "$m_2$", "$v_{i_2}$", "$v_{f_1}$", "$v_{f_2}$"]) elastic_collision_table.set_data(table_data) "print(elastic_collision_table.latex())" define make_row(m1, m2, run) as trial_num[0] := trial_num[0] + 1 return [trial_num[0].__int__(), m1, m2, run[1], run[2]] end make_row table_data := flatten(((m1, m2, runs) -> ((run) -> make_row(m1, m2, run))`(runs))`(inelastic_masses_c1, inelastic_masses_c2, inelastic_datasets)) inelastic_collision_table := Table2D() inelastic_collision_table.set_labels(["$m_1$", "$m_2$", "$v_{i_2}$", "$v_{f_1}$"]) inelastic_collision_table.set_data(table_data) "print(inelastic_collision_table.latex())" trial_num[0] := 0 define make_row(momenta_before, momenta_after, ke_before, ke_after) as trial_num[0] := trial_num[0] + 1 return [trial_num[0].__int__(), momenta_before, momenta_after, ke_before, ke_after] end make_row table_data := flatten(make_row**(**elastic_total_momenta_before, **elastic_total_momenta_after, **elastic_total_ke_before, **elastic_total_ke_after)) elastic_calc_table := Table2D() elastic_calc_table.set_labels(["Trial", "$p_i$", "$p_f$", "k_{ei}", "k_{ef}"]) elastic_calc_table.set_data(table_data) "print(elastic_calc_table.latex())" table_data := flatten(make_row**(**inelastic_total_momenta_before, **inelastic_total_momenta_after, **inelastic_total_ke_before, **inelastic_total_ke_after)) inelastic_calc_table := Table2D() inelastic_calc_table.set_labels(["Trial", "$p_i$", "$p_f$", "k_{ei}", "k_{ef}"]) inelastic_calc_table.set_data(table_data) print(inelastic_calc_table.latex())
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
30 sec ago | 0.46 KB
Untitled
1 min ago | 1.07 KB
Untitled
3 min ago | 0.39 KB
Untitled
4 min ago | 0.17 KB
Christmas Gift
23 min ago | 0.84 KB
December smells like money (Release)
CSS | 23 min ago | 0.82 KB
Untitled
29 min ago | 2.94 KB
Untitled
31 min ago | 0.90 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!