Parabola elements calculator

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?
178 Replies
JavaBot
JavaBot2mo ago
This post has been reserved for your question.
Hey @Royalrex25! 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.
Royalrex25
Royalrex25OP2mo ago
I have the first bit done already.
Royalrex25
Royalrex25OP2mo ago
this is urgent
dan1st
dan1st2mo ago
What exactly do you want to do?
ngc0202
ngc02022mo ago
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
Royalrex25
Royalrex25OP2mo ago
true lol
ngc0202
ngc02022mo ago
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
Royalrex25
Royalrex25OP2mo ago
lol, but how do I get user input for specific variables?
dan1st
dan1st2mo ago
You can use a Scanner, BufferedReader or similar on System.in
Royalrex25
Royalrex25OP2mo ago
thanks, how would I tie System.in to A for example? its been a while so I've forgotten
dan1st
dan1st2mo ago
For example
try(Scanner scan = new Scanner(System.in)) {
double a = scan.nextDouble();//read a double and put it in a variable named a
//do more work here
}
try(Scanner scan = new Scanner(System.in)) {
double a = scan.nextDouble();//read a double and put it in a variable named a
//do more work here
}
Royalrex25
Royalrex25OP2mo ago
thanks mate
ngc0202
ngc02022mo ago
Alternatively you could pass them as args, which is what I'd do given the choice
Royalrex25
Royalrex25OP2mo ago
apperantly the readDouble() symbol cannot be found
dan1st
dan1st2mo ago
nextDouble
Royalrex25
Royalrex25OP2mo ago
hmm, never used that method before
dan1st
dan1st2mo ago
it's if you want to pass input to the application before starting it
Royalrex25
Royalrex25OP2mo ago
there we go, now I just need to do that two more times I see ok, so the code can't find symbol A from the double that is defined before that code occurs.
dan1st
dan1st2mo ago
Variables are case sensitive and it needs to be in scope if you define a variable inside a {} block, you can only use it in that block
Royalrex25
Royalrex25OP2mo ago
used uppercase for both
ngc0202
ngc02022mo ago
double a;
try(…) {
a = ...
}
double a;
try(…) {
a = ...
}
Royalrex25
Royalrex25OP2mo ago
I defined A wthin the try area
dan1st
dan1st2mo ago
it's better to write all the code inside the try block here tbh Did you also do the same with the code using a?
ngc0202
ngc02022mo ago
Why? I try to keep try blocks as small as possible with only relevant bits
dan1st
dan1st2mo ago
Also by convention, it's recommended to use camelCase (starting with a lowercase letter) for all variables and methods Because it's System.in and you cannot use it once you closed it
Royalrex25
Royalrex25OP2mo ago
I did both with A, and now the scanner can't use A
dan1st
dan1st2mo ago
I mean technically closing System.in isn't necessary but IMO it's good to get used to it
Royalrex25
Royalrex25OP2mo ago
due to predefinition in main block
dan1st
dan1st2mo ago
Can you show your code?
ngc0202
ngc02022mo ago
I'd presume he's reading his three things and being done with stdin
dan1st
dan1st2mo ago
you don't know
Royalrex25
Royalrex25OP2mo ago
here's the updated code so far
dan1st
dan1st2mo ago
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);
}
}
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);
}
}
Royalrex25
Royalrex25OP2mo ago
that fixed it now I just need to get B and C defined from user input as well and then I can do the rest (hopefully)
dan1st
dan1st2mo ago
Do you know how?
Royalrex25
Royalrex25OP2mo ago
use the same method as A?
dan1st
dan1st2mo ago
yes
Royalrex25
Royalrex25OP2mo ago
do I need to close the A method? or is it fine without that?
dan1st
dan1st2mo ago
?
Royalrex25
Royalrex25OP2mo ago
I mean close the scanner for A
dan1st
dan1st2mo ago
You should use the same scanner for all inputs and the try(){} block automatically closes the scanner at the end
Royalrex25
Royalrex25OP2mo ago
cuz I need 3 different values for A B and C to be different
dan1st
dan1st2mo ago
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) if you run nextDouble 3 times, it will read 3 values one after each other
Royalrex25
Royalrex25OP2mo ago
I see.. ahh, so how can I add a text prompt to nextDouble to make sure the use knows what each is for?
dan1st
dan1st2mo ago
System.out.println I assume you are able to use it?
Royalrex25
Royalrex25OP2mo ago
ik how to use system.out.println but I wanted to make sure there wasn't some convaluted method. and im guessing I put one before each double is scanned?
dan1st
dan1st2mo ago
It should be fine with println
Royalrex25
Royalrex25OP2mo ago
yeah, but does each one go before or after the scan.nextdouble?
dan1st
dan1st2mo ago
Do you want to first show the user something or get data from the user?
Royalrex25
Royalrex25OP2mo ago
I want to show them the prompt first so that they know what their inputing/what to do but I also don't want all three going at once
dan1st
dan1st2mo ago
then execute the corresponding things in that order
ngc0202
ngc02022mo ago
Why is this tagged "recursion" and "maven" lol
Royalrex25
Royalrex25OP2mo ago
recursion??? my bad, should be fixed so, how do I portray -b in java for the vertex?
dan1st
dan1st2mo ago
?
Royalrex25
Royalrex25OP2mo ago
cuz I got -75 from A = 10, B = 25 and the formula for a vertex is -b/2a thats why im asking
dan1st
dan1st2mo ago
I am not sure what you mean with vertex
Royalrex25
Royalrex25OP2mo ago
im doing a parabola solver
dan1st
dan1st2mo ago
What exactly are you doing and what's the issue with that? so?
Royalrex25
Royalrex25OP2mo ago
I don't think I should be getting -75 from that set
dan1st
dan1st2mo ago
idk what you mean with solving - Do you want to find roots? and idk the code you wrote
Royalrex25
Royalrex25OP2mo ago
thats later, im trying to solve the vertex with this point ill get the code for ya
dan1st
dan1st2mo ago
I have no idea what you mean with solving a vertex Do you want to evaluate the function at a specific point?
dan1st
dan1st2mo ago
I have no idea what you mean with vertex
Royalrex25
Royalrex25OP2mo ago
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
dan1st
dan1st2mo ago
-B/2*A is -(B/2)*A I think you might want -B/(2*A)
Royalrex25
Royalrex25OP2mo ago
Thanks, hope this works now im getting -1.25 I should be getting -7ish what did I do wrong?
dan1st
dan1st2mo ago
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
Royalrex25
Royalrex25OP2mo ago
the point of which a parabola with this set of values mirrors itself is at -7 (values being A=10, B=25, C=8) , the program spit out -1.25 instead. here is my current code which seems to work just fine apart from the vertex calculation
dan1st
dan1st2mo ago
No description
Royalrex25
Royalrex25OP2mo ago
you forgot to add C being 8
dan1st
dan1st2mo ago
That doesn't change the result
dan1st
dan1st2mo ago
here's with C=8
No description
dan1st
dan1st2mo ago
but I created it before you wrote the thing about C=8
Royalrex25
Royalrex25OP2mo ago
No description
Royalrex25
Royalrex25OP2mo ago
thats where it should be
dan1st
dan1st2mo ago
that's pretty much -1.25 Do you want the y-value? If so, you'd have to calculate it by applying the function
Royalrex25
Royalrex25OP2mo ago
its -7.8, how is that -1.25???? lol now that seems a bit rude of me, sorry about that
dan1st
dan1st2mo ago
No description
Royalrex25
Royalrex25OP2mo ago
now that makes sense, Ive forgotten how to do parabola calculations, Im sorry for my oversight
dan1st
dan1st2mo ago
no problem
Royalrex25
Royalrex25OP2mo ago
wait, how do I do squared in java?
dan1st
dan1st2mo ago
x*x or Math.pow(x,2)
Royalrex25
Royalrex25OP2mo ago
ight, and im trying to apply the xVertex value to the original equation but it keeps erroring out, I'll share the code
dan1st
dan1st2mo ago
^2is not squaring
Royalrex25
Royalrex25OP2mo ago
now that makes sense, but what about the rest of it? was that the only fix?
dan1st
dan1st2mo ago
idk, what is the error you are getting?
Royalrex25
Royalrex25OP2mo ago
how do I fix the "possibly lousy conversion from double to int" on the xVertex = vertexformulaX; line? doing a proper square fixed the first issue
dan1st
dan1st2mo ago
change the int xVertex to double xVertex; int means it's for integers i.e. no numbers with a decimal point double is for floating point numbers
Royalrex25
Royalrex25OP2mo ago
and, why am I getting a new error on the last double line before my final printing line?
dan1st
dan1st2mo ago
because if you do string concatenation, the result is a String not a double double is for floating point numbers, not for text
Royalrex25
Royalrex25OP2mo ago
adding the String header to replace the double header still didn't fix the error
dan1st
dan1st2mo ago
What's the error? and idk what you mean with header
Royalrex25
Royalrex25OP2mo ago
cuz im trying to print out the vertex form of the equation but I can't do it straight out with the println function
dan1st
dan1st2mo ago
idk what the issue is if you don't tell me btw vertexFormulaY just holds the value, not the whole formula
Royalrex25
Royalrex25OP2mo ago
yeah, so I'm trying to use the string VertexForm to hold the final formula without calculating it so that it can get printed out in the println fuction below it
dan1st
dan1st2mo ago
What happens?
Royalrex25
Royalrex25OP2mo ago
well, I get a giant block of errors due to the way its formatted presumably
dan1st
dan1st2mo ago
"X" + + " - " you have + + there
Royalrex25
Royalrex25OP2mo ago
the two main errors I get are ";" expected and that it's not a statement
dan1st
dan1st2mo ago
I don't think that's intended .
Royalrex25
Royalrex25OP2mo ago
fixed it, but I still get the same errors I still have to do the roots after I fix this part
dan1st
dan1st2mo ago
I can't tell you what the issue is without seeing the errors my guess is unmatching {}
Royalrex25
Royalrex25OP2mo ago
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
Royalrex25
Royalrex25OP2mo ago
heres the up to date code
dan1st
dan1st2mo ago
if you want me to help you, you need to show me the exact errors
Royalrex25
Royalrex25OP2mo ago
I did right here its on the String [] VertexForm line
dan1st
dan1st2mo ago
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;
Royalrex25
Royalrex25OP2mo ago
yeah, I want that string to print out the actual one when running
dan1st
dan1st2mo ago
.
Royalrex25
Royalrex25OP2mo ago
gives me the "";" expected" and "not a statement" errors
dan1st
dan1st2mo ago
on which line?
Royalrex25
Royalrex25OP2mo ago
the string VertexForm line
dan1st
dan1st2mo ago
How did you change the line now?
Royalrex25
Royalrex25OP2mo ago
I copy pasted, and replaced the old string line
dan1st
dan1st2mo ago
ah you forgot a + symbol before xVertex
Royalrex25
Royalrex25OP2mo ago
that fixed it, I jsut tested the code and somehow the program got -148.25 for the vertex idk how
dan1st
dan1st2mo ago
you did vertexFormulaY = A*xVertex*A+B*xVertex+C; That's A^2 x+Bx+C
Royalrex25
Royalrex25OP2mo ago
so how do I fix it?
dan1st
dan1st2mo ago
read the line and ask yourself why it does that
Royalrex25
Royalrex25OP2mo ago
ohh wait, the lack of brackets right?
dan1st
dan1st2mo ago
no
Royalrex25
Royalrex25OP2mo ago
what else could it be? im honestly at a loss
dan1st
dan1st2mo ago
What do you want to do with that line?
Royalrex25
Royalrex25OP2mo ago
get the Yvalue of the vertex
dan1st
dan1st2mo ago
Using the formula for a parabola. What is the formula for a parabola?
Royalrex25
Royalrex25OP2mo ago
y = Ax^2+Bx+C
dan1st
dan1st2mo ago
And what's that line doing?
Royalrex25
Royalrex25OP2mo ago
squaring A and adding the rest together? I think idk thought it would work
dan1st
dan1st2mo ago
Is A squared in this formula?
Royalrex25
Royalrex25OP2mo ago
A*x is
dan1st
dan1st2mo ago
?
Royalrex25
Royalrex25OP2mo ago
ohh, wait so I gotta add brackets then
dan1st
dan1st2mo ago
no
Royalrex25
Royalrex25OP2mo ago
what else could I do?
dan1st
dan1st2mo ago
What is squared in the formula? A*x is not what's squared
Royalrex25
Royalrex25OP2mo ago
A is squared? sorry, its been a while
dan1st
dan1st2mo ago
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
Royalrex25
Royalrex25OP2mo ago
so x is squared then? lol
dan1st
dan1st2mo ago
yes - in the formula
Royalrex25
Royalrex25OP2mo ago
so I jsut change the 2nd A to an X?
dan1st
dan1st2mo ago
hm?
Royalrex25
Royalrex25OP2mo ago
so I do xVertexXVertex? ranther than XVertexA? there we go, that fix it. now all I need to do is the roots and then im done idk how to translate it into java code though would you be willing to help me out with getting the steps translated?
dan1st
dan1st2mo ago
maybe
Royalrex25
Royalrex25OP2mo ago
maybe? wdym? why "maybe" what would it take for you to help me translate the steps?
dan1st
dan1st2mo ago
depends on whether I'm sleeping, whether you are showing what exactly you have an issue with, etc
Royalrex25
Royalrex25OP2mo ago
well, I have been showing you what i've been struggling with 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
dan1st
dan1st2mo ago
you sue * for the multiplications or do you mean finding the values r and s?
Royalrex25
Royalrex25OP2mo ago
yeah, cuz I don't fully remember what r and s co-respond to I just need a working way of getting the roots from A B and C
dan1st
dan1st2mo ago
the roots which you can get using the abc formula?
Royalrex25
Royalrex25OP2mo ago
and the X and Y values for the vertex if needed
dan1st
dan1st2mo ago
abc formula?
Royalrex25
Royalrex25OP2mo ago
yeah, how would I use the data given to find it in java? 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
dan1st
dan1st2mo ago
The abc formula is (-b +- sqrt(b^2-4ac))/2a
Royalrex25
Royalrex25OP2mo ago
and this would allow me to display the roots?
dan1st
dan1st2mo ago
this is the formula for the roots, yes one root with +, one root with -
Royalrex25
Royalrex25OP2mo ago
anything specific I need to do to show them?
dan1st
dan1st2mo ago
if your task requires anything specific $$ \frac{-b\pm\sqrt{b^2-4ac}}{2a} $$
TeXit
TeXit2mo ago
No description
dan1st
dan1st2mo ago
^ that formula
Royalrex25
Royalrex25OP2mo ago
would needing to print both roots count?
dan1st
dan1st2mo ago
Doesn't seem hard
Royalrex25
Royalrex25OP2mo ago
and the original formula for the roots gives me "")" or ";" expected", "";" expected", and "not a statement"
dan1st
dan1st2mo ago
because the formula isn't valid Java code you have to translate it first
Royalrex25
Royalrex25OP2mo ago
how?
dan1st
dan1st2mo ago
What do you think?
Royalrex25
Royalrex25OP2mo ago
idk lol, im terrible with java and would I need to use two different formulas?
dan1st
dan1st2mo ago
yes one with +, one with -
Royalrex25
Royalrex25OP2mo ago
ohh, thats what that meant
dan1st
dan1st2mo ago
and you can calculate square roots in Java with Math.sqrt(PUT_YOUR_RADICANT_HERE)
Royalrex25
Royalrex25OP2mo ago
wait, you mean one with -4ac and one with +4ac right?
dan1st
dan1st2mo ago
no there is a +- symbol in the formula Maybe you should first learn how quadratic equations work before implementing it
Royalrex25
Royalrex25OP2mo ago
oh, wait a minute, now I remember thanks for all the help dude, its been a few months since i've done anything with parabola's 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);
dan1st
dan1st2mo ago
looks about right
Royalrex25
Royalrex25OP2mo ago
cool, thanks for all the help with this
JavaBot
JavaBot2mo ago
Post Closed
This post has been closed by <@595765455436644367>.
Want results from more Discord servers?
Add your server