Roots of Quadratic Equations

Link to the project here.

The project is quite simple: plug in the variables a, b, and c as found in the equation a(x^2)+bx+c=0, and you'll get the root(s) of the equation.

Numbers are rounded to the hundredths place. Also, there is support for complex numbers (plug in a=5, b=2, c=1 to get the solution set [-0.2 + 0.4i, -0.2 - 0.4i]).

Nice project. One little thing that I think you don't know about Snap! is that you can use the left-facing arrowhead in the LIST block so that it looks like this: Roots%20of%20Quadratic%20Equations%20script%20pic and it reports an empty list, so you don't have to delete that empty item later.

Do you know about building your own blocks?

Link to the project again, if you want to see the update.

Oops, I forgot about that trick with lists.

Anyways while making this project I did make an block that tested if the discriminant was imaginary but it broke for some reason. I've made six new (working) blocks now:

  • Reporter Discriminant Block : Returns the discriminant when plugging in a, b, and c, but won't tell you if the discriminant is imaginary (that's for the other block)
  • Predicate Discriminant Block : Returns a Boolean based upon whether or not the discriminant calculated with the a, b, and c values is a real number.
  • Round to Decimal Place Block : Rounds to the decimal place.
  • Add (Real/Imaginary) Solutions Block : Adds the solutions of a quadratic equation to the solutions list (formatted differently if the solutions involve imaginary numbers).
  • (Real/Imaginary) Component Block : Only used when dealing with imaginary solutions.
  • Quadratic Numerator Block : Finds the numerator '-b ± sqrt((b^2) - (4ac))'. Has built in ± determination (plug in a + or a -).

So now, the Predicate Discriminant Block will return a Boolean that will tell the project whether to add real or imaginary solutions to the list, and then calculate those solutions.

Now the code is a bit simpler, and I've broken it down quite a bit so it isn't as confusing to read as before.

Great! One more trick I think you'll want to know about is that you can have a dropdown menu as an input, so you can use that instead of text inputs for "real" vs. "imaginary" etc.: Open the long form input dialog, then right-click on the background of the dark grey box. Choose "options." This will open a dialog box in which you enter the choices, one per line. Click OK. Then, back in the long form input dialog, right-click again and check "read-only." This will give you a block-colored input slot, like the first input to SET. (Otherwise you get a white text entry box with a menu, like the first input to ITEM.)

A quibble on vocabulary: "Real" and "imaginary" are the right choices for the COMPONENT block, but in the ADD ___ SOLUTIONS block it should be "real" and "complex."

This is a matter of taste and not everyone will agree, but I don't like the "add solutions to a list" command block. I'd rather make SOLUTIONS a reporter, that reports (LIST ___ ___). Then instead of a Solutions variable and an X variable, I'd just say

Roots%20of%20Quadratic%20Equations%20script%20pic

where "solutions..." is the reporter with inputs a,b,c and the menu for real/complex. To get that "input list:" format you drop the "solutions" block on the arrowheads -- look for a red halo when you're in the right place.

(Sorry -- I'm a teacher -- it's hard for me not to teach. :-))

Appropriate changes have been made.

I'm quite new to Snap! and I must say thank you for teaching me on the dropdown menus and the input list trick. Next time I make a project I'll be sure to keep those in mind.

You're welcome. Now I have a confession to make: I never actually ran your project to the end before. Now that I see it run, I think it'd look better if you skip the CALL (JOIN...) business and just directly SAY the list you get from SOLUTIONS.

On the two Chromebooks and one Windows desktop (also with the Chrome browser), I can't see inside the project. I get the expected Opening project... box, but then I get a white screen (maybe a few morphs).

Yeah, this is a known Chrome bug. It's fixed in their next release, so make sure you're up to date.

On my school device, Gopher Buddy and chrome://settings/help say that Chrome is up to date, but whatismybrowser.com says it's not.
(Same results on my personal device except that I don't Gopher Buddy there.)

Yeah, that means there's a released beta that's ahead of the regular official release.

For some reason, when I open your project, this happens. It does not happen on any other projects, though.Any ideas on what this is?

Try it again with Chrome 88 and Snap! 5.2.1.