Pure Programmer
Blue Matrix


Cluster Map

Project: Milky Way Stellar Density Estimate

Estimate the average [[stellar density]] of the [[Milky Way]] Galaxy. The stellar density is the number of stars per volume. Assume that the volume of the Milky Way is calculated as in project MilkyWayVolume and that the number of stars is 100 - 400 billion. Because we don't know the exact number of stars, allow the user to pass the number of stars in on the command line.

Also compute the size of box with a star in the middle that would correspond to the stellar density calculated. (Hint: Take the cube root of the reciprocal of the stellar density) This is the average distance between stars if the the galaxy were homogenious (which it is not) and if stars were stacked in little boxes of the same size (which they are not). What would the number of stars need to be in order to correspond to the distance to our nearest neighbor star [[Proxima Centauri]] at 4.2465 light-years?

Output
$ rustc MilkyWayStellarDensity.rs error[E0425]: cannot find value `args` in this scope --> MilkyWayStellarDensity.rs:15:5 | 15 | if args.len() != 2 { | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> MilkyWayStellarDensity.rs:17:3 | 17 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::process::exit; | error[E0425]: cannot find value `Utils` in this scope --> MilkyWayStellarDensity.rs:19:25 | 19 | let mut numStars:i64 = Utils.stoiWithDefault(args[1], 250000000000_i64); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> MilkyWayStellarDensity.rs:19:47 | 19 | let mut numStars:i64 = Utils.stoiWithDefault(args[1], 250000000000_i64); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0425]: cannot find value `PI` in this scope --> MilkyWayStellarDensity.rs:21:23 | 21 | let diskVolume:f64 = PI * pow(DISK_RADIUS - BULGE_RADIUS,2.f64) * DISK_THICKNESS; | ^^ not found in this scope | help: consider importing one of these items | 8 + use consts::PI; | 8 + use std::f32::consts::PI; | error[E0425]: cannot find value `PI` in this scope --> MilkyWayStellarDensity.rs:22:43 | 22 | let sphereVolume:f64 = 4.0f64 / 3.0f64 * PI * pow(BULGE_RADIUS,3.0f64); | ^^ not found in this scope | help: consider importing one of these items | 8 + use consts::PI; | 8 + use std::f32::consts::PI; | warning: unused import: `std::f64::consts` --> MilkyWayStellarDensity.rs:8:5 | 8 | use std::f64::consts; | ^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default error[E0308]: mismatched types --> MilkyWayStellarDensity.rs:10:27 | 10 | static BULGE_RADIUS:f64 = 10000; | ^^^^^ | | | expected `f64`, found integer | help: use a float literal: `10000.0` error[E0308]: mismatched types --> MilkyWayStellarDensity.rs:11:26 | 11 | static DISK_RADIUS:f64 = 52850; | ^^^^^ | | | expected `f64`, found integer | help: use a float literal: `52850.0` error[E0308]: mismatched types --> MilkyWayStellarDensity.rs:12:29 | 12 | static DISK_THICKNESS:f64 = 1000; | ^^^^ | | | expected `f64`, found integer | help: use a float literal: `1000.0` error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> MilkyWayStellarDensity.rs:21:61 | 21 | let diskVolume:f64 = PI * pow(DISK_RADIUS - BULGE_RADIUS,2.f64) * DISK_THICKNESS; | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 21 | let diskVolume:f64 = PI * pow(DISK_RADIUS - BULGE_RADIUS,2.0f64) * DISK_THICKNESS; | + error[E0425]: cannot find function `pow` in this scope --> MilkyWayStellarDensity.rs:21:28 | 21 | let diskVolume:f64 = PI * pow(DISK_RADIUS - BULGE_RADIUS,2.f64) * DISK_THICKNESS; | ^^^ not found in this scope error[E0425]: cannot find function `pow` in this scope --> MilkyWayStellarDensity.rs:22:48 | 22 | let sphereVolume:f64 = 4.0f64 / 3.0f64 * PI * pow(BULGE_RADIUS,3.0f64); | ^^^ not found in this scope error[E0425]: cannot find function `pow` in this scope --> MilkyWayStellarDensity.rs:26:28 | 26 | let averageDistance:f64 = pow(stellarDensity,-1.0f64 / 3.0f64); | ^^^ not found in this scope error: aborting due to 13 previous errors; 1 warning emitted Some errors have detailed explanations: E0308, E0425, E0610. For more information about an error, try `rustc --explain E0308`. $ rustc MilkyWayStellarDensity.rs error[E0425]: cannot find value `args` in this scope --> MilkyWayStellarDensity.rs:15:5 | 15 | if args.len() != 2 { | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> MilkyWayStellarDensity.rs:17:3 | 17 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::process::exit; | error[E0425]: cannot find value `Utils` in this scope --> MilkyWayStellarDensity.rs:19:25 | 19 | let mut numStars:i64 = Utils.stoiWithDefault(args[1], 250000000000_i64); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> MilkyWayStellarDensity.rs:19:47 | 19 | let mut numStars:i64 = Utils.stoiWithDefault(args[1], 250000000000_i64); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0425]: cannot find value `PI` in this scope --> MilkyWayStellarDensity.rs:21:23 | 21 | let diskVolume:f64 = PI * pow(DISK_RADIUS - BULGE_RADIUS,2.f64) * DISK_THICKNESS; | ^^ not found in this scope | help: consider importing one of these items | 8 + use consts::PI; | 8 + use std::f32::consts::PI; | error[E0425]: cannot find value `PI` in this scope --> MilkyWayStellarDensity.rs:22:43 | 22 | let sphereVolume:f64 = 4.0f64 / 3.0f64 * PI * pow(BULGE_RADIUS,3.0f64); | ^^ not found in this scope | help: consider importing one of these items | 8 + use consts::PI; | 8 + use std::f32::consts::PI; | warning: unused import: `std::f64::consts` --> MilkyWayStellarDensity.rs:8:5 | 8 | use std::f64::consts; | ^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default error[E0308]: mismatched types --> MilkyWayStellarDensity.rs:10:27 | 10 | static BULGE_RADIUS:f64 = 10000; | ^^^^^ | | | expected `f64`, found integer | help: use a float literal: `10000.0` error[E0308]: mismatched types --> MilkyWayStellarDensity.rs:11:26 | 11 | static DISK_RADIUS:f64 = 52850; | ^^^^^ | | | expected `f64`, found integer | help: use a float literal: `52850.0` error[E0308]: mismatched types --> MilkyWayStellarDensity.rs:12:29 | 12 | static DISK_THICKNESS:f64 = 1000; | ^^^^ | | | expected `f64`, found integer | help: use a float literal: `1000.0` error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> MilkyWayStellarDensity.rs:21:61 | 21 | let diskVolume:f64 = PI * pow(DISK_RADIUS - BULGE_RADIUS,2.f64) * DISK_THICKNESS; | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 21 | let diskVolume:f64 = PI * pow(DISK_RADIUS - BULGE_RADIUS,2.0f64) * DISK_THICKNESS; | + error[E0425]: cannot find function `pow` in this scope --> MilkyWayStellarDensity.rs:21:28 | 21 | let diskVolume:f64 = PI * pow(DISK_RADIUS - BULGE_RADIUS,2.f64) * DISK_THICKNESS; | ^^^ not found in this scope error[E0425]: cannot find function `pow` in this scope --> MilkyWayStellarDensity.rs:22:48 | 22 | let sphereVolume:f64 = 4.0f64 / 3.0f64 * PI * pow(BULGE_RADIUS,3.0f64); | ^^^ not found in this scope error[E0425]: cannot find function `pow` in this scope --> MilkyWayStellarDensity.rs:26:28 | 26 | let averageDistance:f64 = pow(stellarDensity,-1.0f64 / 3.0f64); | ^^^ not found in this scope error: aborting due to 13 previous errors; 1 warning emitted Some errors have detailed explanations: E0308, E0425, E0610. For more information about an error, try `rustc --explain E0308`.

Solution