SRL Archive - RS3 Outdated / Broken Scripts

Quadratic Equation Solver


Baked0420

2009-09-23 23:02:17

Made this because I got easily side-tracked while doing homework, and I could use it to make sure I'm doing my homework right. I guess you guys can use it to check/do your homework also :p whatever you decide. The first pop-up box it just to make sure you understand how a quadratic equation should be set-up, just hit enter. Then you imput a, b, and c and the script does the rest.

By the way, I'm in pre-calc, this stuff is just review.

EDIT: Oh forgot to mention, there is no setup you need to do before running the script, just run it then like I said above, you imput a, b, and c. (ax^2 + bx + c = 0)

If you use this a simple thank you would be appreciated :)

Features:

-Quadratic Formula
-imaginary numbers
-Cubic Formula
-Pop-up box to declare which formula to use, and to imput the base numbers of the equation
-Leaves numbers that aren't perfect squares in the radical, so you don't get a big decimal answer


Future:

-Shorten coding
-Add Quartic formula
-Maybe make the output look better
-Maybe add custom form


Changelog:

Version 1.0: Initial release
Version 1.1: Added support for imaginary numbers
Version 1.2: Added the cubic equation solver, fixed some bugs (dealing with imaginary numbers) (V1.2 is ComplexEquationSolver.Scar)

Baked0420

2009-09-24 07:11:19

bump, I don't know if anyone will start caring, but if you had a negative number inside the radical it couldn't solve it since you can't do the square root of a negative number. It now supports square roots of negative numbers using i (imaginy number), I figured I'd add this in since I have problems dealing with i in my homework. Someone should use this ;), I see I got 4 views, I don't think any were from me, maybe one, just to make sure it looked right when opened. Uploading new version now.

Main

2009-09-24 07:45:01

Can you make a solver for cubic, quartic, and quintic :D

Baked0420

2009-09-24 07:50:24

I believe I learned cubic, I will have to jog my memory, but I never heard of quartic or quintic, but I will try to learn the formula and apply it, so I'll give it a shot.

Not really important, but I actually did hear of quartic yesterday, I forgot how to factor by grouping and I asked a smart kid that's in my principles of comp science class (I have to take it since it's a pre-requisite for AP computer science, and I'm as Sr. so I take both at once) and I forgot it was called grouping, but showed him the part I remembered, and after a minute he realized what I was trying to do, and he said ohh grouping, that's for quartic, I was like WTF? Quartic? lol, but yea, pointless story, just mentioning the one time I heard of it. Well I'll refresh my memory on cubic, and then see if I can learn quartic an quintic real fast, or at least there formulas.

You better love me for giving up time to do this :p

EDIT: Quartic formula: http://www.1728.com/quartic2.htm

Looks like I can do it, but it looks a little long, and it's midnight, I'll do it tomorrow :)

still gotta look up cubic and quintic.

EDIT2: cool I love f'ing with urls, I changed quartic to cubic, and what do you know, they have as much creativity as a 13 y/o web designer would, they have the same url for cubic formulas, only with cubic where quartic was :p

cubic: http://www.1728.com/cubic2.htm

quintic is probably the same too, if they have it, I'll check


EDIT3:
either they don't have quintic or the url wasn't what I expected I'll google it.


EDIT4:
wikipedia doesn't make quintic look too fun, I'll see tomorrow if I can find a better website that makes it look more promising. So far I think I should have cubic and quartic solved, but not so sure bout the quintic.

Time for bed now though, in 14 hours I'll be getting home from school and I'll solve the first two then look up quintic again (14 hours, because not everyone is on the same time, should be bout 14 hours from my last edit time, 12:10 for USA east coast, I think that's -5GMT)

Neehosoft

2009-09-24 07:53:26

I'll use for mine

marpis

2009-09-24 21:44:40

There's no solving formula for 5th degree functions…
Here's your next challenge: Find imaginary roots too ;)
x^2 = -1

EDIT: Wow, it does already? o_O Nice work dude

Baked0420

2009-09-24 23:27:42

yep, that was my latest version ;)

my last two problems I tested my script with said it was having a problem, I instantly knew it had to be a problem with imaginary numbers so I added it and it works now, and that's what about the quintic function from wikipedia, which is why I said I'm not so sure bout a solver for that one :p.

Well I gotta go to the eye doctor today for a follow-up on getting contacts a week ago, then I'll put in the cubic and quartic functions and make a spot to choose which solver to use.

And thank you very much for telling me nice work :D

Naum

2009-09-24 23:27:57

Mine:


Var A, B, C : Extended;
Ans : Array [0..1] Of Extended;
Astr, Bstr, Cstr : String;

begin
Astr := ReadLn('What is the value of A in an integer form');
Bstr := ReadLn('What is the value of B in an integer form');
Cstr := ReadLn('What is the value of C in an integer form');
A := StrToFloatDef(Astr, 0);
B := StrToFloatDef(Bstr, 0);
C := StrToFloatDef(Cstr, 0);
wait(8);
Ans[0] := (-B + Sqrt(Sqr(B) - (4* A * C))) div (2 * A);
Ans[1] := (-B - Sqrt(Sqr(B) - (4* A * C))) div (2 * A);
WriteLn('The answer is X = '+FloatToStr(Ans[1])+', Or X = '+FloatToStr(Ans[0]));
end.

E: Lol, it's pretty basic compared to yours :p

Dan Cardin

2009-09-24 23:55:49

actually give the roots as roots with the +- fractions instead of the usually useless decimals. That would make me happier =)

Baked0420

2009-09-25 00:06:34

c'mon, always gotta steal my glory :p

pretty nice, very short and looks efficient, I could shorten mine a lot, but I posted mine right after testing, so I never bothered to turn things into one line like you.

But mine still has one thing on yours, imaginary numbers, so even though mines a bit longer when it could easily be shortened, mine still has an edge on your's because I don't think your's can handle imaginaries.


And I am about half way done with the cubic (switched quartic to cubic in this first edit, realized I said the wrong one :p) equation, but I'm leaving now to go to the eye doctor, I couldn't resist starting though :p


EDIT: Dan cardin, I was thinking bout that today in school, how when it's not a perfect square in the radical, we usually leave it as -b plus/minus the square root of the discriminant over 2a. Sorry for writing it out like that, I started to write it without words but it didn't look good, by the way, for anyone who doesn't know (since I didn't till two days ago in pre-calc), the discriminant is b^2-4ac, the part in the radical.

I will probably add that in the next version, or the version after the cubic and quartic formulas.


EDIT:

Status update: Still working on the cubic function, so far I got it done for all the roots being equal, now I just need to make it solve all roots being real and for only one real root. I thought I'd get this done today, but I took a break for a while in the middle, so I only finished 1 outta 3 pieces, I should have the cubic function done by tomorrow now, and hopefully have it added into the quadratic formula script with an option for which formula to use.

Then I need to add the quartic formula. Then I will work on what me and dan cardin said if I'm still into this project and if I feel it's worth it, getting replies/views/thank yous or people just in general using it.

Baked0420

2009-09-26 09:03:29

New post for a new update, I now have the cubic equation solved, and there is an option to choose which solver. Also, there is a bugfix, when you got an answer with i, say 12+5i over 6, it would say 17i over 6. I now have it fixed for when it uses i's (quadratic formula). The quadratic formula now also shouldn't give you decimals, if the discriminant isn't a perfect square, it'll leave it alone and write it out how me and dan cardin said. Uhm, I don't know what else, I guess if you use this and see that an answer is wrong, post the equation and I'll work on fixing it.