Anyone Know Where to Find Code That Solves Quartic Equations in Lua?

Hello,
I am currently looking for code that is able to solve quartic equations, most likely through inputting the coefficients of the equation. I would much prefer if this code source was in Lua as the code from what I have seen is long and complex math wise, which I would not want to translate back into Lua.

1 Like

Unless youā€™re doing some second-degree derivative ballistic trajectory equation mumbo jumbo, I donā€™t see any practical use case for quartic equations within a Roblox game

I mean, if it looks like this I doubt anyone has converted a quartic formula into programming language form

1 Like

I am getting a turret to predict a path with gravity affecting the bullet. People have converted it, but not into Lua from what Iā€™ve seen, which might take some time to convert.

It looks like youā€™re going to be the first one to do so then.

Thereā€™s this article: https://github.com/CasualX/ProjectileSolverDemo

And then thereā€™s also this:

Which claims to ā€œcompensate for gravityā€ which Iā€™ve yet to test for myself

He mentioned exponential gravity, is that some sort of pseudo gravity or just regular gravity?

I have no idea; like I said, I havenā€™t tested the gravity compensation myself, only went as far as opening up the demo and having a peek

I canā€™t really understand the language of the website you linked, it is using a language I have never used myself, but I did find a C written one. I am confused about one part of it. Each function has parameters of c and s, do you by any chance know what each might correlate too? I believe they are both arrays just donā€™t know what they are specified for.
(Was clicking on the wrong website somehow, looking over it now though)

ā€œcā€ appears to be the input and ā€œsā€ is the output. The function themselves doesnā€™t return the solution, they instead plop it inside the ā€œsā€ table which contains all real solutions

Would c be ordered from greatest power to lowest power? For example 7x^2+3x+17 would go in as
[7, 3, 17]?

Dude you have the source code in front of you

It also literally tells you that at the top within the comment block

1 Like

Use rational root theorem.

Hi

Yeah right now the moduleā€™s a bit broken, Iā€™ll see if I can fix it and re-send the model
thanks for letting me know nonetheless

Hi itā€™s me again so I just found this cool math module that uses Newton iteration to solve polynomials

It seems to be working fine for me (except for that duplicate answer)

1 Like

Hi, would you mind giving the function you graphed in the image, I want to fix the duplicate answer problem and use that function to check if its fixed or not

0.1*x^4 + x^3 + 2.5*x^2 + 0.8*x - 1

Looking at your module it seems like you can fix it by adding a precision threshold for the hash table check so that minuscule differences wonā€™t matter

1 Like

Fixed, turns out math.round isnt practical when eliminating very similar answers from tables, thanks for the help!

Just ended up translating the github I linked and works perfectly.

you know i already did everything

also there was a native Lua formula for quartics, you just had to dig deeper

We are using the same sources and the translation of the code doesnā€™t take long at all so honestly Iā€™d rather write it myself, but thanks.