Advertisement
Agent_Silence

Math ax^2+bx+c=y solver

Feb 25th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.70 KB | None | 0 0
  1.  
  2. local tArgs = {...}
  3. function signFix(eq)
  4. if eq == math.abs(eq) then
  5.     return "+"..eq
  6. else
  7.     return eq
  8. end
  9. end
  10.  
  11. tArgs[2] = tArgs[2]/tArgs[1]
  12. tArgs[3] = tArgs[3]/tArgs[1]
  13. tArgs[4] = tArgs[4]/tArgs[1]
  14. print("x^2 "..signFix(tArgs[2]).."x "..signFix(tArgs[3]).." = "..tArgs[4])
  15. print("x^2 "..signFix(tArgs[2]).."x "..signFix(((tArgs[2]/2)^2)).." = "..((tArgs[4]-tArgs[3])+((tArgs[2]/2))^2))
  16. print("(x "..signFix((tArgs[2]/2))..")^2 = "..((tArgs[4]-tArgs[3])+((tArgs[2]/2))^2))
  17. print("x "..signFix((tArgs[2]/2)).." = "..((tArgs[4]-tArgs[3])+((tArgs[2]/2))^2)^0.5)
  18. print("x = "..(0-(tArgs[2]/2)+((tArgs[4]-tArgs[3])+((tArgs[2]/2))^2)^0.5).." or "..(0-(tArgs[2]/2)-((tArgs[4]-tArgs[3])+((tArgs[2]/2))^2)^0.5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement