# -*- coding: utf-8 -*-
"""
Created on Fri Dec 09 14:12:45 2016

@author: Lama Hamadeh
"""

#The ratio of the areas of a circle and the square inscribing it is pi / 4. 
#In this six-part exercise, we will find a way to approximate this value.

#-------------------------------------------------

#2a
#Using the math library, calculate and print the value of pi / 4.


import math
from math import pi

x = math.pi/4

#print(x)

#-------------------------------------------------

#2b
#Using random.uniform, create a function rand() that generates a single float between -1 and 1.
#Call rand() once. So we can check your solution, we will use random.seed to fix the value called 
#by your function.


import random

random.seed(1) # This line fixes the value called by your function,
               # and is used for answer-checking.

def rand():
   return random.uniform(-1, 1)

rand()

#-------------------------------------------------

#2c
#The distance between two points x and y is the square root of the sum of squared differences along 
#each dimension of x and y. Create a function distance(x, y) that takes two vectors and outputs the 
#distance between them. Use your function to find the distance between (0,0) and (1,1).
#Print your answer.

def distance(x, y): #x,y are points 
    dist = math.sqrt((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 )#the first point x=(x0,y0)
    #and the second point y=(x1,y1). The distance between two points is given by:
        #distance = sqrt((x0-x1)^2+(y0-y1)^2)
    return dist
    
print(distance((0,0),(1,1)))

#-------------------------------------------------

#2d
#distance(x, y) is pre-loaded from part 2c. Make a function in_circle(x, origin) that uses distance 
#to determine if a two-dimensional point falls within the the unit circle with a given origin. 
#That is, find if a two-dimensional point has distance <1 from the origin (0,0).
#Use your function to print whether the point (1,1) lies within the unit circle centered at (0,0).

def in_circle(x, origin = [0]*2):
   return distance(x, origin) < 1
   
print(in_circle( (1,1) ))

#-------------------------------------------------

#2e

    



@@ -2080,13 +2080,13 @@
 n = 
-%5B0%5D*2
+(0,0)
 ):%0D%0A
@@ -2120,19 +2120,16 @@
 n) %3C 1%0D%0A
-   
 %0D%0Aprint(
@@ -2142,80 +2142,727 @@
 cle(
- 
 (1,1)
- ))%0D%0A%0D%0A#-------------------------------------------------%0D%0A%0D%0A#2e%0D%0A
+,(0,0))) #This results False as the point resides outside the unit circle. %0D%0A#if we choose another point, let say (0.5, 0.5), the resut would be tru as the point sets inside the unit cirlce.%0D%0A#-------------------------------------------------%0D%0A%0D%0A#2e%0D%0A#The functions rand and in_circle are defined from previous exercises. %0D%0A#Using these functions, code is pre-entered that creates a list x of R=10000 %0D%0A#two-dimensional points. Create a list of 10000 booleans called inside that are %0D%0A#True if and only if the point in x with that index falls within the unit circle. %0D%0A#Make sure to use in_circle!%0D%0A#Print the proportion of points within the circle. %0D%0A#This proportion is an estimate of the ratio of the two areas!
 %0D%0A  

Update Homework_Week1_2.py