Negative variable for quadratic equation

Hello,


My problem is that I want to make a negative variable. I am making an app which will calculate a quadratic equation. I am sending you a screenshot of the blocks too. It always writes that it has a problem with the part where it must do -1*b_p. I am using a formula of a quadratic equation: (-b±√(b²-4ac))/(2a). I also tried to make a special variable for -1. It would be great if you help me.
Thank you in advance for your help.

1 Like

quadraticEquation.aia (16.6 KB)

1 Like

Regarding your original blocks, there are some corrections and advice:

  • The values entered in the Text Boxes are TextboxN.Text, not the component block.

  • Just refer to those .Text values in the Click event. It is more reliable than that Lost Focus technique.

  • Switch the blocks to External Inputs mode to see the nesting more clearly than Inline mode.

2 Likes

I want to ask you if you know, how to make a quadratic function graph. I changed blocks like this and now it solves a quadratic equation but I must have a graph too. It would be great if you help me.

The AI2 graph block s are flexible, and can adjust their domains and ranges to fit whatever set of (x,y) pairs you feed them.

But it is up to you to count up your x values from some starting value, match them with y values, and feed them to the graph.

https://community-appinventor-mit-edu.ezproxy.canberra.edu.au/t/testing-the-chart-component/58847/5?u=abg

Thank you, but I have not worked with graph in mit app inventor before and I must send it in a few days. I want to ask you, what I must change or add when I want it to work.

(Canned Reply: ABG- Export & Upload .aia)
Export your .aia file and upload it here.
export_and_upload_aia

kvadraticka.aia (31.5 KB)

In this post I will list what you did wrong in your app, before working on fixing it.

In your Designer, you added a Chart component, but you did not add the subcomponent of the Chart that is meant to hold all the (x,y) points of the chart.

You have 3 text boxes for a,b,c (good), but you have no text boxes to enter the desired domain of x values you want to chart. That is not x1,x2 (the roots of the equation.)

You also lack a button to request plotting the chart.

Blocks:

You have two global init (y1 and y2) that depend on the text box values of a,b,c. However, those are always empty at startup. Just leave those 0 in the init, to be filled in later.

When you calculate values for x1 and x2 using that formula, you are solving for the roots of the quadratic equation. The roots are the places where the graph crosses the x axis (y=0), right?

So what if the graph is a parabola floating above the x axis, not touching it?
Maybe you will get imaginary numbers for x1 and x2?
No problem, AI2 can handle imaginary numbers.

The graph Entry Click event is inappropriate here, because it has no entries to click yet, lacking a ChartData2D subcomponent.


kvadraticka1.aia (31.8 KB)

This adds a graph, with domain from -10 to 10.

I leave it to you if you want to generalize it more.

3 Likes

Thank you very much for your help.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.