alzami Posted December 15, 2013 Share Posted December 15, 2013 (edited) 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 December 15, 2013 by alzami Link to comment Share on other sites More sharing options...
davej Posted December 15, 2013 Share Posted December 15, 2013 Imaginary numbers again? Link to comment Share on other sites More sharing options...
alzami Posted December 15, 2013 Author Share Posted December 15, 2013 (edited) 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 December 15, 2013 by alzami Link to comment Share on other sites More sharing options...
davej Posted December 15, 2013 Share Posted December 15, 2013 It seems that it will not raise a negative number to a fractional power. Link to comment Share on other sites More sharing options...
alzami Posted December 15, 2013 Author Share Posted December 15, 2013 Math.pow(-1,0.33) is also not giving any value.how can it be done? Link to comment Share on other sites More sharing options...
davej Posted December 15, 2013 Share Posted December 15, 2013 There is no need to calculate roots of negative numbers. Link to comment Share on other sites More sharing options...
alzami Posted December 15, 2013 Author Share Posted December 15, 2013 var for_cube_root2=(1/2)*(three-root); it is -0.39;its ok; i have to calculate -0.30 to the power 0.33.its in the formula.thats what cube2 does.but not working though. Link to comment Share on other sites More sharing options...
alzami Posted December 15, 2013 Author Share Posted December 15, 2013 i have made it this way and its working.. var cube2=-(Math.pow(-for_cube_root2,0.33)); a negative sign in front of Math.pow and inside bracket befor for_cube_root2.is there any better way to do it.if there please let me know Link to comment Share on other sites More sharing options...
Ingolme Posted December 15, 2013 Share Posted December 15, 2013 I believe the problem arises because 0.33 is not exactly one third, so an imaginary component, a small one, probably exists. Link to comment Share on other sites More sharing options...
alzami Posted December 15, 2013 Author Share Posted December 15, 2013 (edited) codes of my previous comment works and matches with roots calculated by sci calc.but still feeling confused Edited December 15, 2013 by alzami Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now