English

# how to solve two equations with programming - Javascript

solving equations

## Snippet Code

 Rate this page :     [ 0 votes]

Following are the steps to solve any two linear equations using javascript:1. Change the linear equations into array notation example: eq1 => 5x 4y = 33 eq2 => 6x 2y = 13 will be,//first equation var eq1 = new Array(3); eq1=5; eq1=4; eq1=33;//second equation var eq2 = new Array(3); eq2=6; eq2=2; eq2=13; 2. Add the 'solveEqns' and 'findDeter' functions in your code and call the above 'solveEqns' function and store the result in an array. var ans = new Array(2); ans=solveEqns(eq1,eq2);3. Show the x value and y value document.write("x= " ans "
y= " ans);

<script> //include this script in the head tag //function to solve two equations function solveEqns(eq1,eq2) { var ans = new Array(2); var a1=eq1; var b1=eq1; var c1=eq1; var a2=eq2; var b2=eq2; var c2=eq2; ans=findDeter(c1,b1,c2,b2)/findDeter(a1,b1,a2,b2); ans=findDeter(a1,c1,a2,c2)/findDeter(a1,b1,a2,b2); //alert(ans); return ans; } //function to find the determinant function findDeter(a,b,c,d) { var d=(a*d)-(c*b); return d; } </script>