I have an assignment to make a program that can calculate the area beneath a graph in a certain area. My function is f(x)=3+(tan(x))^2 I have turned this into javascript so it looks like this:
var y = 3 + Math.pow(Math.tan((x)*(180/Math.PI)), 2) This is giving the right result at certain x-values. But sometimes, eg. at x = 3.4, it gives a strange number like 16 where I expected something around 3 or 4.
I have read that it can be caused by the problem with floating point behavior, but it should not give that big a difference? I don't understand it. :(
I use a for loop to change the x value and and array to store the values.
Math.tan((x)*(180/Math.PI))Uh? Why are you converting to degrees there?Math.tan()expects radians.