Open your browser's debug console and paste this in:
function solveSecondOrderODE(b, c, y0, dy0, dt, tMax) {
let t = 0;
let y = y0;
let dy = dy0;
while (t <= tMax) {
console.log(`At time ${t.toFixed(2)}: y = ${y.toFixed(4)}`);
let ddy = -b * dy - c * y; // Compute the acceleration (second derivative)
y += dy * dt; // Update position
dy += ddy * dt; // Update velocity
t += dt;
}
}
// Example usage:
// Constants b and c for the damped harmonic oscillator
const b = 0.5;
const c = 1.0;
// Initial conditions: y0 (initial position), dy0 (initial velocity)
const y0 = 1.0;
const dy0 = 0.0;
// Time step (dt) and maximum time (tMax)
const dt = 0.1;
const tMax = 10;
solveSecondOrderODE(b, c, y0, dy0, dt, tMax);
The basic concepts translate well from other languages like say, Python.
I work for a major University. The only major numerate discipline for which we do not teach programming to undegraduates is Medicine, and my guess is that Medics are already completely buried by the tremendous amount of stuff they're expected to have at least some knowledge of to do their eventual jobs, without us showing them how to make apps.
Like sure, if you come here to study Fine Art, we don't (by default) teach you to write software, but if you come to learn like mech eng. or electronics or chemistry or something you're going to be shown how to write software. You can probably flunk that in most of these subjects and still get a degree because it's not on your critical path, but we tried.
These are not software engineering courses. You're not going to learn how to be in charge of a major software project, you won't learn how to design software, nor even stuff like CI and revision control - if you try to scale what you learned in one course as a Biologist into a Chrome-sized application that's going to be a disaster, but you've written software, you know what a loop is, what a variable is, and so on.