litalela
|
  |
| Joined: 30 Mar 2010 |
| Total Posts: 6267 |
|
|
| 29 Jul 2015 08:56 PM |
Okay, so I made this really simple script to solve the quad formula:
script.Parent.MouseButton1Down:connect(function() local a = tonumber(script.Parent.Parent.aVal.Text) local b = tonumber(script.Parent.Parent.bVal.Text) local c = tonumber(script.Parent.Parent.bVal.Text) local answer1 = (((0 - b) + (math.sqrt((b * b) - (4 * a * c)))) / 2) local answer2 = (((0 - b) - (math.sqrt((b * b) - (4 * a * c)))) / 2) print(answer1, answer2) end)
However if one of the values is 0 it breaks. Any reason why? |
|
|
| Report Abuse |
|
|
litalela
|
  |
| Joined: 30 Mar 2010 |
| Total Posts: 6267 |
|
|
| 29 Jul 2015 09:01 PM |
| crap i forgot its 2a not 2 |
|
|
| Report Abuse |
|
|
baldo46
|
  |
| Joined: 28 Jul 2008 |
| Total Posts: 1254 |
|
|
| 29 Jul 2015 09:01 PM |
Discriminant must be > 0.
There are no imaginary numbers in programming. |
|
|
| Report Abuse |
|
|
litalela
|
  |
| Joined: 30 Mar 2010 |
| Total Posts: 6267 |
|
|
| 29 Jul 2015 09:03 PM |
Even when discriminant is > 0 this doesnt work. e.e roblox why, this was way easier with java.
For y=x^2 + 4*x - 16 it says the roots are -2 and -2, wtf did I do wrong |
|
|
| Report Abuse |
|
|
baldo46
|
  |
| Joined: 28 Jul 2008 |
| Total Posts: 1254 |
|
|
| 29 Jul 2015 09:08 PM |
| try looking at what cval is set to.. WINK WINK |
|
|
| Report Abuse |
|
|
litalela
|
  |
| Joined: 30 Mar 2010 |
| Total Posts: 6267 |
|
|
| 29 Jul 2015 09:09 PM |
| DANG IT CHRIST I HATE MY LIFE |
|
|
| Report Abuse |
|
|
Marzlyn
|
  |
| Joined: 15 Jun 2014 |
| Total Posts: 4431 |
|
| |
|
litalela
|
  |
| Joined: 30 Mar 2010 |
| Total Posts: 6267 |
|
|
| 29 Jul 2015 09:14 PM |
| now to make it work with imaginary numbers |
|
|
| Report Abuse |
|
|
baldo46
|
  |
| Joined: 28 Jul 2008 |
| Total Posts: 1254 |
|
|
| 29 Jul 2015 09:24 PM |
answer = math.sqrt(math.abs(discriminant));
if (discriminant < 1) then answer = "i" .. answer; end |
|
|
| Report Abuse |
|
|
litalela
|
  |
| Joined: 30 Mar 2010 |
| Total Posts: 6267 |
|
|
| 29 Jul 2015 09:25 PM |
baldo i was about to make a complicated ass thing
thank you |
|
|
| Report Abuse |
|
|
baldo46
|
  |
| Joined: 28 Jul 2008 |
| Total Posts: 1254 |
|
|
| 29 Jul 2015 09:28 PM |
Make sure you don't make the answer equal that though. Remember it's (-b +- (that value)) / (2a)
So obviously some fiddling to do with it, but yourwelcome. |
|
|
| Report Abuse |
|
|
litalela
|
  |
| Joined: 30 Mar 2010 |
| Total Posts: 6267 |
|
|
| 29 Jul 2015 09:36 PM |
script.Parent.MouseButton1Down:connect(function() local a = tonumber(script.Parent.Parent.aVal.Text) local b = tonumber(script.Parent.Parent.bVal.Text) local c = tonumber(script.Parent.Parent.cVal.Text) local i = false local part1 = (0-b) local part2 = (b * b) local part3 = (4 * a * c) local part4 = (part2 - part3) if part4 < 1 then part4 = math.abs(part4) i = true end local discriminant = (math.sqrt(part4)) local part6a = (part1 + discriminant) local part6b = (part1 - discriminant) local part7 = (2 * a) local part8a = (part6a / part7) local part8b = (part6b / part7) if i == true then local part6a = (part1 + discriminant .. "i") local part6b = (part1 - discriminant .. "i") local part7 = (2 * a) local part8a = (part6a .. "/" .. part7) local part8b = (part6b .. "/" .. part7) print(part8a, part8b) end if i == false then print(part8a, part8b) end end)
not perf but itll do |
|
|
| Report Abuse |
|
|