Use * to indicate multiplication: Type 4*x for 4x;

Use ^ to indicate powers: Type 4*x^3 for 4×3; 12*x^-6 for 12x?6.

Use parentheses to delimit the argument of a function; i.e., type sin(x) rather than sin x.

Use parentheses to define the scope of an operation: For example, type 4*x*(x^2+1)^3 for 4x(x2+1)3; 4^(2*x+1) for 42x+1; (sin(x))^2 for (sin(x))2.

Do not type sin^2(x) for sin2(x), type (sin(x))^2 instead.

Do not use brackets [ ] or braces { }, use only parentheses to delimit a mathematics expression.

Functions you may use:

– Trig: sin, cos, tan, cot, sec, csc;

– Inverse Trig: asin, acos, atan;

– Log/exponential: ln (naturall og), or use log; exp, the naturalexp onential; Note: You can also enter the natural exponential exp(x) as e^x for ex.

– Misc.: sqrt, usage sqrt(x) for ?x (or, use exponential notation: x^(1/2)).

When you enter your response, some attempt will be made to determine whether the response is a valid one. For example, if you say san(x), the function ‘san’ will not be recognized as a valid mathematicalfunction; an error message is generated, and the user is not penalized for a possible typing error. The JavaScript routines will also check for unbalanced parentheses; thus, ((x^4+1) + sin(x)^2 will be flagged as a syntax error.
Important: The only variable used is x; do not enter any other undefined symbols into your answer.

Subscribe to getButterfly Blog

Once a week or so we send an email with our best content. We never bug you, we just send you our latest piece of content.

If you found any value in this post, agree, disagree, or have anything to add - please do. I use comments as my #1 signal for what to write about. Read our comment policy before commenting! Comments such as "Thank you!", "Awesome!", "You're the man!" are either marked as spam or stripped from URL.

4 thoughts on “Numerical Integration Using JavaScript”

I don’t understand – are these native functions of javascript, or are you discussing some framework or some such?

No, it’s just examples on how to use mathematical functions. I am working on some JavaScript game and I’m using mathematical calculations. Here are some examples of mistakes, I’ve run into, and how to use parentheses, groups, and delimitations.

Ah, ok – I got confused when you said, ‘The only variable used is x; do not enter any other undefined symbols into your answer’ – do you mean you can use x without defining it?

I don’t understand – are these native functions of javascript, or are you discussing some framework or some such?

No, it’s just examples on how to use mathematical functions. I am working on some JavaScript game and I’m using mathematical calculations. Here are some examples of mistakes, I’ve run into, and how to use parentheses, groups, and delimitations.

Ah, ok – I got confused when you said, ‘The only variable used is x; do not enter any other undefined symbols into your answer’ – do you mean you can use x without defining it?

No. You should define ‘x’ first. The formulas will calculate different results (based on what you need), based on the value of ‘x’.