2 years ago

#68995

test-img

AstralV

Making a little angular resolution calculator in JS but it returns NaN

So, I'm in an astronomy class, and don't have a scientific calculator yet, so as a side project practice sometimes I'll translate a math question that would otherwise be tedious into a JS program so it can do physics math for me (like, last week i made an escape velocity function rather than punching in math individually to calculate escape velocity for multiple objects).

This new question basically states that Arcsine of theta = lightspeed/diameter of observation point (this is the equation the prof offered, though he said for the sake of simplicity we can use 1.00 rather than 1.22 in this measure as it is more precisely known). I've designed a function to take diameter as a parameter and return the answer, but when I run it it just consoles NaN, I wonder if it's my logic or syntax that is faulting me or just poor math. I'm pretty rusty, but enjoy doing little side practices to probe into my comprehension of math equations and whatnot. If anyone felt like pointing out where I went wrong, it would help me diagnose what aspect of this process I am not retaining. I'm also like 4 drinks in and it's 1:30am tho lol this I guess is how I choose to spend my time. here goes:

let lightspeed = 3*Math.pow(10,8);

function Aungular (diameter){
    let ans1 =lightspeed/diameter;
    let ans =Math.asin(ans1);

    console.log(ans);
}

Aungular(20); // returns NaN

What am I messing up? Oh, also I have like no trig experience haha, so it's important that I diagnose early on if this is what's causing whatever I overlooked.

(I hope that this doesn't cross any boundaries -- no coding is relevant to the assignment - this is something I'm doing on my own time as a brain exercise to increase my depth of understanding for math problems and exercise practice for writing code more fluently).

Edit: I mixed placements for diameter and lightspeed, program runs if they are switched. Solved, I guess. It's always the simplest stuff that I miss haha

javascript

logic

calculator

trigonometry

0 Answers

Your Answer

Accepted video resources