#Parabola elements calculator

273 messages · Page 1 of 1 (latest)

sudden mulch
#

so, im trying to write a program what would calculate the direction of opening, vertex, y intercept, zeros, and vertex form of the equation. how would I go about doing that?

restive palmBOT
#

This post has been reserved for your question.

Hey @sudden mulch! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

sudden mulch
#

I have the first bit done already.

#

this is urgent

robust trail
#

What exactly do you want to do?

manic oar
#

The first step would be to figure out how to do each of these things mathematically

#

Then it'd be a relatively simple task of translating that into Java

manic oar
#

Once you've done that, if you get stuck writing some specific piece in Java, I think that'd be a more appropriate question for here

#

If we told you how to do the math we'd just be doing your homework for you

sudden mulch
robust trail
sudden mulch
robust trail
manic oar
#

Alternatively you could pass them as args, which is what I'd do given the choice

sudden mulch
robust trail
sudden mulch
robust trail
sudden mulch
sudden mulch
robust trail
#

and it needs to be in scope

#

if you define a variable inside a {} block, you can only use it in that block

sudden mulch
manic oar
#
double a;
try(…) {
   a = ...
}
sudden mulch
robust trail
robust trail
manic oar
#

Why? I try to keep try blocks as small as possible with only relevant bits

robust trail
#

Also by convention, it's recommended to use camelCase (starting with a lowercase letter) for all variables and methods

robust trail
sudden mulch
robust trail
#

I mean technically closing System.in isn't necessary but IMO it's good to get used to it

sudden mulch
#

due to predefinition in main block

robust trail
manic oar
#

I'd presume he's reading his three things and being done with stdin

sudden mulch
#

here's the updated code so far

robust trail
# sudden mulch

I'd move the code after the try block inside the try block

#

and you were redeclaring the variable i.e. you'd have two variables named A

#
try(Scanner scan = new Scanner(System.in)) {
    double a = scan.nextDouble();
    //int parabolaEqualtion = f(x)=A*x^2+B*x+C;
    double dirOfOpening = a;
    if (dirOfOpening < 0) {
        String trueDirOfOpening = "up";
        System.out.println(trueDirOfOpening);
    }
}

sudden mulch
#

now I just need to get B and C defined from user input as well

#

and then I can do the rest (hopefully)

robust trail
sudden mulch
robust trail
#

yes

sudden mulch
#

do I need to close the A method?

#

or is it fine without that?

robust trail
sudden mulch
robust trail
#

You should use the same scanner for all inputs

#

and the try(){} block automatically closes the scanner at the end

sudden mulch
robust trail
#

Note that you don't really need to close System.in (and Scanners on it), that's your choice - but closing is important with some other IO (e.g. files or networking)

robust trail
sudden mulch
robust trail
#

I assume you are able to use it?

sudden mulch
robust trail
#

It should be fine with println

sudden mulch
robust trail
sudden mulch
#

but I also don't want all three going at once

robust trail
manic oar
#

Why is this tagged "recursion" and "maven" lol

sudden mulch
sudden mulch
sudden mulch
robust trail
#

?

sudden mulch
#

cuz I got -75 from A = 10, B = 25

#

and the formula for a vertex is -b/2a

#

thats why im asking

robust trail
#

I am not sure what you mean with vertex

sudden mulch
robust trail
#

What exactly are you doing and what's the issue with that?

robust trail
sudden mulch
#

I don't think I should be getting -75 from that set

robust trail
#

idk what you mean with solving - Do you want to find roots?

#

and idk the code you wrote

sudden mulch
#

ill get the code for ya

robust trail
#

I have no idea what you mean with solving a vertex

#

Do you want to evaluate the function at a specific point?

sudden mulch
robust trail
#

I have no idea what you mean with vertex

sudden mulch
#

basically, the vertex is the point at which it intersects with it's line of symmtry

#

or the point at which a parabola changes direction

#

so if one side is facing one way, the vertex is the point at which it mirrors itself

robust trail
#

-B/2*A is -(B/2)*A

#

I think you might want -B/(2*A)

sudden mulch
#

Thanks, hope this works

sudden mulch
#

I should be getting -7ish

#

what did I do wrong?

robust trail
#

What exactly did you enter? What is the exact code you executed now?

#

And why should it be -7 instead of e.g. -1.25?

#

-5/4 seems like the correct value when I view a parabola with a=10, b=25

sudden mulch
sudden mulch
robust trail
#

That doesn't change the result

#

here's with C=8

#

but I created it before you wrote the thing about C=8

sudden mulch
sudden mulch
robust trail
#

Do you want the y-value? If so, you'd have to calculate it by applying the function

sudden mulch
#

lol

#

now that seems a bit rude of me, sorry about that

robust trail
sudden mulch
robust trail
#

no problem

sudden mulch
#

wait, how do I do squared in java?

robust trail
#

or Math.pow(x,2)

sudden mulch
robust trail
#

^2is not squaring

sudden mulch
#

was that the only fix?

robust trail
#

idk, what is the error you are getting?

sudden mulch
sudden mulch
robust trail
#

int means it's for integers i.e. no numbers with a decimal point

#

double is for floating point numbers

sudden mulch
robust trail
#

because if you do string concatenation, the result is a String

#

not a double

#

double is for floating point numbers, not for text

sudden mulch
#

adding the String header to replace the double header still didn't fix the error

robust trail
#

What's the error?

#

and idk what you mean with header

sudden mulch
#

cuz im trying to print out the vertex form of the equation but I can't do it straight out with the println function

robust trail
#

idk what the issue is if you don't tell me

#

btw vertexFormulaY just holds the value, not the whole formula

sudden mulch
robust trail
#

What happens?

sudden mulch
robust trail
#

"X" + + " - "

#

you have + + there

sudden mulch
#

the two main errors I get are ";" expected and that it's not a statement

robust trail
#

I don't think that's intended

robust trail
sudden mulch
#

fixed it, but I still get the same errors

#

I still have to do the roots after I fix this part

robust trail
#

I can't tell you what the issue is without seeing the errors

#

my guess is unmatching {}

sudden mulch
#

I added the {} brackets but it give me more and new errors

#

such as "}" expected and ";" expected and not a statement

#

hmm, and I still need to do the zeros after I get this part done

robust trail
#

if you want me to help you, you need to show me the exact errors

sudden mulch
#

I did

sudden mulch
#

its on the String [] VertexForm line

robust trail
#

oh String[] VertexForm = {"y=", + A + "(" + "X" + " - " xVertex + ")" + vertexFormulaY}; is not valid

#

Do you want a single String?

#

if yes, just do String VertexForm = "y=" + A + "(" + "X" + " - " xVertex + ")" + vertexFormulaY;

sudden mulch
sudden mulch
robust trail
#

on which line?

sudden mulch
robust trail
#

How did you change the line now?

sudden mulch
#

I copy pasted, and replaced the old string line

robust trail
#

ah you forgot a + symbol

#

before xVertex

sudden mulch
#

idk how

robust trail
#

you did vertexFormulaY = A*xVertex*A+B*xVertex+C;

#

That's A^2 x+Bx+C

sudden mulch
robust trail
#

read the line and ask yourself why it does that

sudden mulch
robust trail
#

no

sudden mulch
#

what else could it be?

#

im honestly at a loss

robust trail
#

What do you want to do with that line?

sudden mulch
robust trail
#

Using the formula for a parabola.

#

What is the formula for a parabola?

sudden mulch
robust trail
sudden mulch
#

I think

#

idk

#

thought it would work

robust trail
sudden mulch
robust trail
#

?

sudden mulch
#

ohh, wait

#

so I gotta add brackets then

robust trail
#

no

sudden mulch
robust trail
#

What is squared in the formula?

#

A*x is not what's squared

sudden mulch
#

A is squared? sorry, its been a while

robust trail
#

In the formula for a parabola? No, A shouldn't be squared there

#

Are you doing that? Yes

#

Is it done in the formula for parabolas? No

sudden mulch
#

so x is squared then? lol

robust trail
#

yes - in the formula

sudden mulch
#

so I jsut change the 2nd A to an X?

robust trail
#

hm?

sudden mulch
#

so I do xVertex*XVertex?

#

ranther than XVertex*A?

sudden mulch
#

and then im done

#

idk how to translate it into java code though

sudden mulch
sudden mulch
#

wdym?

sudden mulch
#

what would it take for you to help me translate the steps?

robust trail
#

depends on whether I'm sleeping, whether you are showing what exactly you have an issue with, etc

sudden mulch
#

and ik you aint asleep rn lol

#

how would i translate the y=a(x-r)(x-s) into my program?

#

I think thats the only formula I need for the roots

#

unless im wrong

robust trail
#

or do you mean finding the values r and s?

sudden mulch
#

I just need a working way of getting the roots from A B and C

robust trail
sudden mulch
#

and the X and Y values for the vertex if needed

sudden mulch
#

cuz I found a formula D=B^2-4AC

#

idk how well it would work in java but if I could get it working, that would be great

#

cuz I need to display the roots after their calculated

robust trail
sudden mulch
robust trail
#

one root with +, one root with -

sudden mulch
robust trail
#

if your task requires anything specific

#

$$
\frac{-b\pm\sqrt{b^2-4ac}}{2a}
$$

jovial heraldBOT
robust trail
#

^ that formula

sudden mulch
robust trail
#

Doesn't seem hard

sudden mulch
robust trail
#

because the formula isn't valid Java code

#

you have to translate it first

sudden mulch
#

how?

robust trail
#

What do you think?

sudden mulch
sudden mulch
robust trail
sudden mulch
robust trail
#

and you can calculate square roots in Java with Math.sqrt(PUT_YOUR_RADICANT_HERE)

sudden mulch
#

wait, you mean one with -4ac and one with +4ac right?

robust trail
#

no

#

there is a +- symbol in the formula

#

Maybe you should first learn how quadratic equations work before implementing it

sudden mulch
#

oh, wait a minute, now I remember

sudden mulch
#

are these the right ones?

double rootCalculation1 = (-B + Math.sqrt(B * B - 4 * A * C)) / (2 * A);
double rootCalculation2 = (-B - Math.sqrt(B * B - 4 + A * C)) / (2 * A);

robust trail
#

looks about right

sudden mulch