Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

JavaScript NKTg Law Mercury Orbit Simulation in JavaScript

NKTgLaw

New Coder
// NKTg Law Mercury Orbit Simulation
// Based on constant position–momentum parameter

// Constant parameter
const C = 8.90e38;

// Mass values
const mass2025 = 3.301e23;

// 2025 position dataset (meters)
const positions2025 = [
{ date: "1/1/2025", x: 5.16e10, vNASA: 53400 },
{ date: "4/1/2025", x: 6.97e10, vNASA: 38900 },
{ date: "7/1/2025", x: 5.49e10, vNASA: 50400 },
{ date: "10/1/2025", x: 6.83e10, vNASA: 39800 },
{ date: "12/31/2025", x: 4.61e10, vNASA: 58900 }
];

// Compute velocity from NKTg Law
function computeVelocity(C, x, m) {
return C / (x * m);
}

// Compute relative error
function computeRelativeError(vModel, vNASA) {
return ((vModel - vNASA) / vNASA) * 100;
}

// Compute NKTg2 term
function computeNKTg2(dm_dt, m, v) {
const p = m * v;
return dm_dt * p;
}

// Mass variation rate
const dm_dt = -0.5;

console.log("NKTg Law Mercury Orbit Simulation Results");
console.log("--------------------------------------------------");

positions2025.forEach(data => {
const vModel = computeVelocity(C, data.x, mass2025);
const error = computeRelativeError(vModel, data.vNASA);
const nktg2 = computeNKTg2(dm_dt, mass2025, vModel);

console.log("Date:", data.date);
console.log("Position (x):", data.x);
console.log("Velocity (Model):", vModel.toExponential(5));
console.log("Velocity (NASA):", data.vNASA);
console.log("Relative Error (%):", error.toFixed(4));
console.log("NKTg2:", nktg2.toExponential(5));
console.log("--------------------------------------------------");
});
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom