Go to Post Hallry's back! Tell a Friend! - Tyler Olds [more]
Home
Go Back   Chief Delphi > Other > Math and Science
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 16-07-2016, 22:00
z_beeblebrox's Avatar
z_beeblebrox z_beeblebrox is online now
Custom User Title
AKA: Cal
FRC #4183 (Bit Buckets)
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Cambridge MA
Posts: 811
z_beeblebrox has a reputation beyond reputez_beeblebrox has a reputation beyond reputez_beeblebrox has a reputation beyond reputez_beeblebrox has a reputation beyond reputez_beeblebrox has a reputation beyond reputez_beeblebrox has a reputation beyond reputez_beeblebrox has a reputation beyond reputez_beeblebrox has a reputation beyond reputez_beeblebrox has a reputation beyond reputez_beeblebrox has a reputation beyond reputez_beeblebrox has a reputation beyond repute
Re: Math Quiz 9

My simple Python Monte Carlo script gave me an average of 0.521408 (or 0.52141 rounded to 5 digits) in ~5e9 iterations (10 miles of hiking worth).

Code is below:
Code:
import numpy as np

iterations = 10000000

avg = 0

for i in range(100000):
    for i in range(iterations):
        pos = np.random.rand(4)
        length = np.sqrt((pos[0]-pos[1])**2+(pos[2]-pos[3])**2)
        avg = (avg*i + length)/(i+1)
    with open("test.txt", "a") as f:
        f.write(str(avg)+'\n')

Code:
import numpy as np

f = np.loadtxt('test.txt')
print(np.average(f))
print(len(f))
I split it into two scripts just so I could stop the computation whenever without altering the result.

Edit: Reps to whoever finds the bug in my code and explains what it does.
__________________
2012 Utah Regional Rookie All-Star
2013 Phoenix Regional Judge's Award for "design process and prototyping"
2014 Hub City Regional Quality Award, Arizona Regional Excellence in Engineering Award
2015 Arizona East Regional Creativity Award, Winner
2016 Arizona North Regional Finalist, Arizona West Excellence in Engineering Award, Finalist

Last edited by z_beeblebrox : 16-07-2016 at 22:57. Reason: New challenge
Reply With Quote
  #2   Spotlight this post!  
Unread 16-07-2016, 22:16
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,995
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Math Quiz 9

Quote:
Originally Posted by z_beeblebrox View Post
0.52141 rounded to 5 digits
That is the correct answer. Reps to you


Reply With Quote
  #3   Spotlight this post!  
Unread 16-07-2016, 21:47
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,995
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Math Quiz 9

Quote:
Originally Posted by Hitchhiker 42 View Post
I ran the Monte Carlo thing in a python script and the answers, each run with 1,000,000 trials, were all around 0.333

Your script has an error.

Compare it to the one-line AWK script I posted.


Reply With Quote
  #4   Spotlight this post!  
Unread 25-07-2016, 12:03
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,531
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Math Quiz 9

OK, another follow-on challenge (cleared with Ether):

What is the average length of all the line segments which can be drawn within the unit circle (1 unit in radius, 2 units in diameter)?

Reps for both the first numeric (good to 1 part per million) and first closed form solution.

Edit: Of course, you must show your work in either case!
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.

Last edited by GeeTwo : 25-07-2016 at 14:05.
Reply With Quote
  #5   Spotlight this post!  
Unread 26-07-2016, 19:42
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,531
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Math Quiz 9

Quote:
Originally Posted by GeeTwo View Post
What is the average length of all the line segments which can be drawn within the unit circle (1 unit in radius, 2 units in diameter)?
This can actually be solved in closed form with much less intricate calculus than the case of the square, with proper selection of coordinate system.

Some warmup questions to this if you can't figure out where to start:
  • What is the average of the squares of the lengths of all the line segments which can be drawn within the unit circle? [taking out the square root simplifies the problem greatly, and helps provide an upper bound to the original question]
  • What is the average of the lengths of all the chords of the unit circle? (That is, line segments with both endpoints on the border of the circle)
  • What is the average of the lengths of all the line segments between a point on the [border of] a circle of radius R, and a point within the same circle?

OBTW, with proper scaling, Greg's answer for the 100000-gon of area 1 provides an answer to the original problem good to within 1 part per 10,000:

Quote:
Originally Posted by Greg Woelki View Post
Here is a generalized Monte Carlo simulation ....
And, OBTW2: if you can find the closed form, each of the four questions can be calculated in fewer than 10 keystrokes on a calculator with the following buttons:
Quote:
0 1 2 3 4 5 6 7 8 9 + - / * π √ =
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #6   Spotlight this post!  
Unread 29-07-2016, 21:57
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,531
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Math Quiz 9

I have posted this figure which I created to describe variables in my calculation of the length of the average line segment from a point on the edge of a circle to a point on the interior. I used this, or a very similar coordinate system, to solve all the "circle questions" except for the one about the mean square of the segments. I am also confident that the same questions can be answered for the sphere using a similar point of view.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #7   Spotlight this post!  
Unread 01-08-2016, 01:23
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,531
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Math Quiz 9

Quote:
Originally Posted by GeeTwo View Post
I am also confident that the same questions can be answered for the sphere using a similar point of view.
I did the integral for the average length of a line segment within a sphere, and found that the answer is rational! This problem was actually simpler to integrate (though just a bit trickier to set up) than any of the two-dimensional problems. If no one posts anything (yes, even a "hold on, I'm working it!") on the circle or sphere questions by Wednesday at 1800 US-CDT, I'll post my solutions so we can close out these quiz questions.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #8   Spotlight this post!  
Unread 03-08-2016, 13:31
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,995
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Math Quiz 9

Quote:
Originally Posted by GeeTwo View Post
I did the integral for the average length of a line segment within a sphere, and found that the answer is rational!
The average length of sphere chords (line segments with both endpoints on sphere surface) is also rational.


Reply With Quote
  #9   Spotlight this post!  
Unread 03-08-2016, 14:52
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,531
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Math Quiz 9

Quote:
Originally Posted by Ether View Post
The average length of sphere chords (line segments with both endpoints on sphere surface) is also rational.
Yes, as well as the intermediate case where one endpoint is on the sphere and the other is internal. I don't recall whether the mean square length was rational or not; I'll check this evening.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #10   Spotlight this post!  
Unread 03-08-2016, 05:02
AMendenhall AMendenhall is offline
Registered User
FRC #3925
 
Join Date: Sep 2015
Location: Ventura
Posts: 22
AMendenhall is an unknown quantity at this point
Re: Math Quiz 9

0.9525383819936485
Sample size: 60 million
Reply With Quote
  #11   Spotlight this post!  
Unread 03-08-2016, 08:13
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,995
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Math Quiz 9

Quote:
Originally Posted by AMendenhall View Post
0.9525383819936485
Sample size: 60 million
Post your code and we'll show you where you went wrong.


Reply With Quote
  #12   Spotlight this post!  
Unread 17-07-2016, 02:34
Aren Siekmeier's Avatar
Aren Siekmeier Aren Siekmeier is offline
on walkabout
FRC #2175 (The Fighting Calculators)
Team Role: Mentor
 
Join Date: Apr 2008
Rookie Year: 2008
Location: 대한민국
Posts: 735
Aren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond repute
Re: Math Quiz 9

Precisely ln(1+sqrt(2))/3 + sqrt(2)/15 + 2/15

Or approximately 0.52140543316
Rounded to 8 digits: 0.52140543
Rounded to 5 digits: 0.52141

A fun exercise in every integration tool I've ever learned, plus a cool rationalization trick I wasn't familiar with.

The computation took a bit to hash through some arithmetic errors and one silly differential error (chain rule!). In practice you probably wouldn't bother to do this (or use a symbolic manipulation tool like Mathematica - this is how I checked my work), and sometimes there is no closed form for the integral. To get 8 digits simply run a larger Monte Carlo simulation (a couple lines of code instead of several pages of derivation). In the end we are always limited to some finite number of digits, so numerical methods win out.
Attached Files
File Type: pdf mathquiz9.pdf (134.2 KB, 64 views)
Reply With Quote
  #13   Spotlight this post!  
Unread 17-07-2016, 10:10
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,531
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Math Quiz 9

Quote:
Originally Posted by Aren Siekmeier View Post
Precisely ln(1+sqrt(2))/3 + sqrt(2)/15 + 2/15

Or approximately 0.52140543316
Rounded to 8 digits: 0.52140543
Rounded to 5 digits: 0.52141

A fun exercise in every integration tool I've ever learned, plus a cool rationalization trick I wasn't familiar with.

The computation took a bit to hash through some arithmetic errors and one silly differential error (chain rule!). In practice you probably wouldn't bother to do this (or use a symbolic manipulation tool like Mathematica - this is how I checked my work), and sometimes there is no closed form for the integral. To get 8 digits simply run a larger Monte Carlo simulation (a couple lines of code instead of several pages of derivation). In the end we are always limited to some finite number of digits, so numerical methods win out.
Wonderful! I've been stuck on the ln(1+√(1+y2)) terms. Didn't think to keep the ln(y) terms with them. (I did the x integrals first, so was using y where you have x-bar).

Edit - Now that I've had a chance to spend more than a few minutes on it, I see that wasn't the trick at all. I just need to go back and re-learn integration by parts.

Edit2: Gathering up my paper notes, this is what I had so far (haven't double-checked everything yet):

Quote:
Originally Posted by GeeTwo View Post
4ʃʃ(1-x)(1-y)√(x2+y2)dxdy, both integrals being over 0..1
Checking the CRC Handbook integrals table (2000 edition):
Quote:
Originally Posted by CRC 2000 Handbook integral #156, ‘+’ case, letting a=y
ʃ√(x2+y2)dx = (x√(x2+y2) + y2 ln(x+√(x2+y2)))/2| = (√(1+y2) + y2 ln(1+√(1+y2)) - y2 lny)/2
Where the | is an implied evaluation over 0..1.

Quote:
Originally Posted by CRC 2000 Handbook integral #163, ‘+’ case, letting a=y
ʃx√(x2+y2)dx = (x2+y2)3/2/3| = ((1+y2)3/2 - y3)/3
  • ʃ(1-y)( (√(1+y2)/2+y2ln(1+√(1+y2))/2-y2lny/2+(1+y2)3/2/3-y3/3)dy
evaluated over y=0..1. This expands to ten terms:
  1. ʃ√(1+y2)dy/2
  2. -ʃy√(1+y2)dy/2
  3. +ʃy2ln(1+√(1+y2))dy/2
  4. -ʃy3ln(1+√(1+y2))dy/2
  5. -ʃy2lnydy/2
  6. +ʃy3lnydy/2
  7. +ʃ(1+y2)3/2dy/3
  8. -ʃy(1+y2)3/2dy/3
  9. -ʃy3dy/3
  10. +ʃy4dy/3

I know or quickly found all but the forms with ln(1+√(1+y2)) in an online table of integrals or the CRC table: http://2000clicks.com/mathhelp/Calcu...rals.aspx#CatL
Quote:
Originally Posted by Term1
ʃ√(y2+1)dy = (√(y2+1) + ln(y+√(y2+1)))/2| = √2 – 1 + ln(1+√2)
Quote:
Originally Posted by Term2
-ʃ√y(y2+1)dy = -(y2+1)3/2/3| = 1/3 - 2√2/3
Quote:
Originally Posted by Term5
+ʃy2lnydy/2 = +y3(lny/3 – 1/9)| = -1/9
Quote:
Originally Posted by Term6
-ʃy3lnydy/2 = +y4(lny/4 – 1/16)| = 1/16
Quote:
Originally Posted by Term7, CRC 164
+ʃ(1+y2)3/2dy/3 = (y(1+y2) 3/2 + 3y(√(y2+1))/2 + 3ln(y+√(y2+1)/2)/12| = √2/6 + √2/8 + ln(1+√2)/8
Quote:
Originally Posted by Term8
-ʃy(1+y2)3/2dy/3 = -(y2+1)5/2/15| = 1/15 - 4√2/15
Quote:
Originally Posted by Term9
-ʃy3dy/3 = -y4/12| = -1/12
Quote:
Originally Posted by Term10
+ʃy4dy/3 = y5/15| = 1/15
I have also worked through term 3, using your same u for integration by parts, and term 4 looks trivially different. Now I'm going to look for a solution that exploits the symmetry between x and y.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.

Last edited by GeeTwo : 17-07-2016 at 15:23.
Reply With Quote
  #14   Spotlight this post!  
Unread 17-07-2016, 15:59
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,995
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Math Quiz 9

Quote:
Originally Posted by Aren Siekmeier View Post
.
Quote:
Originally Posted by GeeTwo View Post
.
Really nice work Aren and Gus.

Here's how I did it.
Attached Thumbnails
Click image for larger version

Name:	numerical double integration solution.png
Views:	82
Size:	11.4 KB
ID:	20915  Click image for larger version

Name:	pdf of abs(rand()-rand()) histogram.png
Views:	62
Size:	17.7 KB
ID:	20916  Click image for larger version

Name:	Octave_dblquad.png
Views:	55
Size:	8.3 KB
ID:	20917  
Reply With Quote
  #15   Spotlight this post!  
Unread 17-07-2016, 17:51
MechEng83's Avatar
MechEng83 MechEng83 is offline
Lead Mentor/Engineer
AKA: Mr. Cool
FRC #1741 (Red Alert)
Team Role: Coach
 
Join Date: May 2011
Rookie Year: 2011
Location: Indiana
Posts: 613
MechEng83 has a reputation beyond reputeMechEng83 has a reputation beyond reputeMechEng83 has a reputation beyond reputeMechEng83 has a reputation beyond reputeMechEng83 has a reputation beyond reputeMechEng83 has a reputation beyond reputeMechEng83 has a reputation beyond reputeMechEng83 has a reputation beyond reputeMechEng83 has a reputation beyond reputeMechEng83 has a reputation beyond reputeMechEng83 has a reputation beyond repute
Re: Math Quiz 9

Now that this has been satisfactorily solved, I'll post a youtube video of this problem that I literally saw the week before Ether posted. I didn't feel right in just posting it, or claiming it as my own solution.

The problem gets to the 4ʃʃ(1-x)(1-y)√(x^2+y^2)dxdy GeeTwo derived, but then it does a polar coordinate substitution to make the integration "easier"
It's another approach which gives a closed form solution, demonstrating that there can be multiple ways to validly solve a problem.
__________________

2016 INWLA GP| INWCH Entrepreneurship | INPMH DCA | INCMP Team Spirit | CAGE Match Winner (w/ 1747 &868), Finalist (1471 w/ 1529 & 1018), Best Fans
2015 ININD Judges Award, Proud "Phyxed Red Card" alliance partners of 1529 & 1720 | INWLA EI | INCMP GP
2014 Boilermaker Creativity | Chesapeake Finalist, Safety, GP, Entrepreneurship | IN State Championship Winner (w/ 868 & 1018) | CAGE Match Winner (w/ 1024, 5402 & 1646)
2013 Boilermaker RCA, Innovation in Controls, Finalist | Crossroads Entrepreneurship | Newton Semi-finalist
2012 Boilermaker Entrepreneurship | Queen City EI | Curie Semi-finalist
2011 Boilermaker RCA, Entrepreneurship
Red Alert Robotics
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:45.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi