Difference between revisions of "DPS915 Toad"

From CDOT Wiki
Jump to: navigation, search
(Assignment 1)
(Assignment 1)
Line 9: Line 9:
 
=== Assignment 1 ===
 
=== Assignment 1 ===
  
Output from Matrix server running each test with time(increasing exponentially by 10^n):
+
==PI Calculation==
  
 +
====Code====
  
sjsaldanha@matrix:~/dps915/assignment1> time w1 10
+
#include <cstdlib>
8/10
+
#include <iostream>
0.8
+
#include <iomanip>
PI = 3.2
+
#include <math.h>
  
real    0m0.022s
+
using namespace std;
user    0m0.008s
 
sys    0m0.004s
 
sjsaldanha@matrix:~/dps915/assignment1> time w1 100
 
81/100
 
0.81
 
PI = 3.24
 
  
real    0m0.015s
+
int main(int argc, char* argv[])
user    0m0.000s
+
{
sys    0m0.008s
+
if(argc < 2)
sjsaldanha@matrix:~/dps915/assignment1> time w1 1000
+
{
775/1000
+
cout<<"Please input the number of circle points"<<endl;
0.775
+
}
PI = 3.1
 
  
real    0m0.016s
+
int npoints = atoi(argv[1]);
user    0m0.000s
+
int circle_count = 0;
sys    0m0.012s
 
sjsaldanha@matrix:~/dps915/assignment1> time w1 10000
 
7858/10000
 
0.7858
 
PI = 3.1432
 
  
real    0m0.018s
+
srand(time(NULL));
user    0m0.000s
 
sys    0m0.012s
 
sjsaldanha@matrix:~/dps915/assignment1> time w1 100000
 
78361/100000
 
0.78361
 
PI = 3.13444
 
  
real    0m0.026s
+
double xValue, yValue;
user    0m0.012s
+
for(int i = 0; i < npoints; i++)
sys    0m0.008s
+
{
sjsaldanha@matrix:~/dps915/assignment1> time w1 1000000
+
//Generate random numbers
785127/1000000
+
xValue = (double) rand()/RAND_MAX;
0.785127
+
yValue = (double) rand()/RAND_MAX;
PI = 3.14051
 
  
real    0m0.123s
+
if(sqrt((xValue*xValue)+(yValue*yValue)) <= 1)
user    0m0.112s
+
{
sys    0m0.004s
+
circle_count++;
sjsaldanha@matrix:~/dps915/assignment1> time w1 10000000
+
}
7855755/10000000
+
}
0.785575
 
PI = 3.1423
 
  
real    0m1.179s
+
double pi, ds;
user    0m1.156s
 
sys    0m0.016s
 
sjsaldanha@matrix:~/dps915/assignment1> time w1 100000000
 
78539030/100000000
 
0.78539
 
PI = 3.14156
 
  
real    0m11.696s
+
cout<<circle_count<<"/"<<npoints<<endl;
user    0m11.645s
+
ds = (double)circle_count/npoints;
sys    0m0.020s
+
cout<<ds<<endl;
sjsaldanha@matrix:~/dps915/assignment1> time w1 1000000000
+
pi = ((4.0)*ds);
785373821/1000000000
 
0.785374
 
PI = 3.1415
 
  
real    1m51.618s
+
cout<<"PI = "<< pi <<endl;
user    1m51.215s
+
 
sys    0m0.016s
+
return 0;
 +
 
 +
}
  
 
=== Assignment 2 ===
 
=== Assignment 2 ===
 
=== Assignment 3 ===
 
=== Assignment 3 ===

Revision as of 13:51, 14 October 2015

Project Name Goes here

Team Members

  1. Sandeep Saldanha
  2. Kris Vukasinovic
  3. ...

Email All

Progress

Assignment 1

PI Calculation

Code

  1. include <cstdlib>
  2. include <iostream>
  3. include <iomanip>
  4. include <math.h>

using namespace std;

int main(int argc, char* argv[]) { if(argc < 2) { cout<<"Please input the number of circle points"<<endl; }

int npoints = atoi(argv[1]); int circle_count = 0;

srand(time(NULL));

double xValue, yValue; for(int i = 0; i < npoints; i++) { //Generate random numbers xValue = (double) rand()/RAND_MAX; yValue = (double) rand()/RAND_MAX;

if(sqrt((xValue*xValue)+(yValue*yValue)) <= 1) { circle_count++; } }

double pi, ds;

cout<<circle_count<<"/"<<npoints<<endl; ds = (double)circle_count/npoints; cout<<ds<<endl; pi = ((4.0)*ds);

cout<<"PI = "<< pi <<endl;

return 0;

}

Assignment 2

Assignment 3