0

I have really not found any good sources where this solution/idea is presented. We started with JavaFX in my class and I have that homework.

I have a equation that should build a graph in JavaFX. I have the canvas ready. For example y = 4x^3 + 3x^2 - 3x + 1.

Here we can calculate some points:

x = -1, y = -4 + 3 + 3 + 1 = 3 
x = 0, y = 1 
x = 1, y = 5 
x = 2, y = 4 * 2^3 + 3 * 2^2 - 3 * 2 + 1 = 39

As I can imagine, the idea is to stake step of about 0.1. But still I have no idea how to code that thing. Professor said, that our code has to solve any cubic equation. Bonus points if graph is centered around extremum points.

Moontego
  • 57
  • 11
  • You know what a loop is? How do you represent the polynomial in code? The extrema are roots of the derivative, can you compute and program it? Do you know the Viete relations between roots and coefficients? – Lutz Lehmann Apr 04 '16 at 13:54
  • Graphing and solving are two very different things. What exactly are you supposed to do? Cubic equations have solutions like quadratic equations; program those if you need to calculate roots. That's different from plotting. – duffymo Apr 04 '16 at 15:09
  • Perhaps this is a duplicate of: [Draw Cartesian Plane Graphi with canvas in JavaFX](http://stackoverflow.com/questions/24005247/draw-cartesian-plane-graphi-with-canvas-in-javafx) – jewelsea Apr 04 '16 at 19:24

1 Answers1

1

If you have to find the extrema anyway, look for the inflection point (root of the second derivative; this is elementary). You can center the plot on this point, as it lies in the middle of the extrema. By finding the roots of the first derivative, you will locate these extrema, if they exist.

By checking the signs of the function at the extrema, you will know how many roots the function has (1 or 3), and where they can be located.

This is enough to find their precise location using the method known as "regula falsi".