Skip to content

Instantly share code, notes, and snippets.

@mdnestor
Created January 21, 2023 23:17
Show Gist options
  • Save mdnestor/2fd10ee0eb3fc1a4bf540852d38b2666 to your computer and use it in GitHub Desktop.
Save mdnestor/2fd10ee0eb3fc1a4bf540852d38b2666 to your computer and use it in GitHub Desktop.
1-dimensional initial-value solver in Rust
fn f(x: Vec<f32>) -> Vec<f32> {
return x;
}
fn main() {
let x0: f32 = 1.0;
let dt: f32 = 0.0001;
let n: usize = 10000;
let mut x: Vec<f32> = vec![x0; n+1];
for i in 1..n {
x[i+1] = x[i] + f(x[i]) * dt;
}
println!("{}", x[n]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment