Jump to content

Math.pow


alzami

Recommended Posts

whay it gives me NAN

Math.pow(-.39,0.33);

if you want u can check my previous posts where i made a calculator and check "x^y" button

actually here var cube2 value is giving NAN;

function solve_cube(){	var m=document.getElementById("gets");	var n=document.getElementById("divs");	n.style.display="none";	var a=prompt("put coeff of x^3");	var b=prompt("put coeff of x^2");	var c=prompt("put coeff of x");	var d=prompt("put value of d");	var front=(-b/(3*a));	var three=2*Math.pow(b,3)-(9*a*b*c)+27*(a*a)*d;	var last=Math.pow((b*b-3*a*c),3);	var under_root=(three*three)-(4*last);	var root=Math.sqrt(under_root);	var for_cube_root1=(1/2)*(three+root);	var for_cube_root2=(1/2)*(three-root);	alert(for_cube_root1);	var cube1=Math.pow(for_cube_root1,0.33);	var cube2=Math.pow(for_cube_root2,0.33);	cube1=(1/(3*a))*cube1;	cube2=(1/(3*a))*cube2;	var x1=front-cube1-cube2;		m.value="x1 = "+x1;		}
Edited by alzami
Link to comment
Share on other sites

no.its for finding roots of cubic equation of type ax3+bx2+cx+d=0..though it has three roots.here is only for the first root x1;

i am testing with a=1,b=1,c=1,d=1.and cube2 is NAN.i tried with my calculator .if i use(-0.30)^0.33 it give me error.but if i put the - sign out or use no bracket it gives value.but cant figure out what is happening with Math.pow function.cube2 is NAN so x1 auto gets NAN

Edited by alzami
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...