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
JavaBot3w 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
Royalrex25OP3w ago
I have the first bit done already.
Royalrex25
Royalrex25OP3w ago
this is urgent
dan1st
dan1st3w ago
What exactly do you want to do?
ngc0202
ngc02023w 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
Royalrex25OP3w ago
true lol
ngc0202
ngc02023w 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
Royalrex25OP3w ago
lol, but how do I get user input for specific variables?
dan1st
dan1st3w ago
You can use a Scanner, BufferedReader or similar on System.in
Royalrex25
Royalrex25OP3w ago
thanks, how would I tie System.in to A for example? its been a while so I've forgotten
dan1st
dan1st3w 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
Royalrex25OP3w ago
thanks mate
ngc0202
ngc02023w ago
Alternatively you could pass them as args, which is what I'd do given the choice
Royalrex25
Royalrex25OP3w ago
apperantly the readDouble() symbol cannot be found
dan1st
dan1st3w ago
nextDouble
Royalrex25
Royalrex25OP3w ago
hmm, never used that method before
dan1st
dan1st3w ago
it's if you want to pass input to the application before starting it
Royalrex25
Royalrex25OP3w 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
dan1st3w 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
Royalrex25OP3w ago
used uppercase for both
ngc0202
ngc02023w ago
double a;
try(…) {
a = ...
}
double a;
try(…) {
a = ...
}
Royalrex25
Royalrex25OP3w ago
I defined A wthin the try area
dan1st
dan1st3w 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
ngc02023w ago
Why? I try to keep try blocks as small as possible with only relevant bits
dan1st
dan1st3w 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
Royalrex25OP3w ago
I did both with A, and now the scanner can't use A
dan1st
dan1st3w ago
I mean technically closing System.in isn't necessary but IMO it's good to get used to it
Royalrex25
Royalrex25OP3w ago
due to predefinition in main block
dan1st
dan1st3w ago
Can you show your code?
ngc0202
ngc02023w ago
I'd presume he's reading his three things and being done with stdin
dan1st
dan1st3w ago
you don't know
Royalrex25
Royalrex25OP3w ago
here's the updated code so far
dan1st
dan1st3w 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
Royalrex25OP3w 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
dan1st3w ago
Do you know how?
Royalrex25
Royalrex25OP3w ago
use the same method as A?
dan1st
dan1st3w ago
yes
Royalrex25
Royalrex25OP3w ago
do I need to close the A method? or is it fine without that?
dan1st
dan1st3w ago
?
Royalrex25
Royalrex25OP3w ago
I mean close the scanner for A
dan1st
dan1st3w ago
You should use the same scanner for all inputs and the try(){} block automatically closes the scanner at the end
Royalrex25
Royalrex25OP3w ago
cuz I need 3 different values for A B and C to be different
dan1st
dan1st3w 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
Royalrex25OP3w 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
dan1st3w ago
System.out.println I assume you are able to use it?
Royalrex25
Royalrex25OP3w 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
dan1st3w ago
It should be fine with println
Royalrex25
Royalrex25OP3w ago
yeah, but does each one go before or after the scan.nextdouble?
dan1st
dan1st3w ago
Do you want to first show the user something or get data from the user?
Royalrex25
Royalrex25OP3w 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
dan1st3w ago
then execute the corresponding things in that order
ngc0202
ngc02023w ago
Why is this tagged "recursion" and "maven" lol
Royalrex25
Royalrex25OP2w ago
recursion??? my bad, should be fixed so, how do I portray -b in java for the vertex?
dan1st
dan1st2w ago
?
Royalrex25
Royalrex25OP2w ago
cuz I got -75 from A = 10, B = 25 and the formula for a vertex is -b/2a thats why im asking
dan1st
dan1st2w ago
I am not sure what you mean with vertex
Royalrex25
Royalrex25OP2w ago
im doing a parabola solver
dan1st
dan1st2w ago
What exactly are you doing and what's the issue with that? so?
Royalrex25
Royalrex25OP2w ago
I don't think I should be getting -75 from that set
dan1st
dan1st2w ago
idk what you mean with solving - Do you want to find roots? and idk the code you wrote
Royalrex25
Royalrex25OP2w ago
thats later, im trying to solve the vertex with this point ill get the code for ya
dan1st
dan1st2w ago
I have no idea what you mean with solving a vertex Do you want to evaluate the function at a specific point?
dan1st
dan1st2w ago
I have no idea what you mean with vertex
Royalrex25
Royalrex25OP2w 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
dan1st2w ago
-B/2*A is -(B/2)*A I think you might want -B/(2*A)
Royalrex25
Royalrex25OP2w ago
Thanks, hope this works now im getting -1.25 I should be getting -7ish what did I do wrong?
dan1st
dan1st2w 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
Royalrex25OP2w 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
dan1st2w ago
No description
Royalrex25
Royalrex25OP2w ago
you forgot to add C being 8
dan1st
dan1st2w ago
That doesn't change the result
dan1st
dan1st2w ago
here's with C=8
No description
dan1st
dan1st2w ago
but I created it before you wrote the thing about C=8
Royalrex25
Royalrex25OP2w ago
No description
Royalrex25
Royalrex25OP2w ago
thats where it should be
dan1st
dan1st2w 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
Royalrex25OP2w ago
its -7.8, how is that -1.25???? lol now that seems a bit rude of me, sorry about that
dan1st
dan1st2w ago
No description
Royalrex25
Royalrex25OP2w ago
now that makes sense, Ive forgotten how to do parabola calculations, Im sorry for my oversight
dan1st
dan1st2w ago
no problem
Royalrex25
Royalrex25OP2w ago
wait, how do I do squared in java?
dan1st
dan1st2w ago
x*x or Math.pow(x,2)
Royalrex25
Royalrex25OP2w 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
dan1st2w ago
^2is not squaring
Royalrex25
Royalrex25OP2w ago
now that makes sense, but what about the rest of it? was that the only fix?
dan1st
dan1st2w ago
idk, what is the error you are getting?
Royalrex25
Royalrex25OP2w 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
dan1st2w 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
Royalrex25OP2w ago
and, why am I getting a new error on the last double line before my final printing line?
dan1st
dan1st2w 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
Royalrex25OP2w ago
adding the String header to replace the double header still didn't fix the error
dan1st
dan1st2w ago
What's the error? and idk what you mean with header
Royalrex25
Royalrex25OP2w 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
dan1st2w ago
idk what the issue is if you don't tell me btw vertexFormulaY just holds the value, not the whole formula
Royalrex25
Royalrex25OP2w 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
dan1st2w ago
What happens?
Royalrex25
Royalrex25OP2w ago
well, I get a giant block of errors due to the way its formatted presumably
dan1st
dan1st2w ago
"X" + + " - " you have + + there
Royalrex25
Royalrex25OP2w ago
the two main errors I get are ";" expected and that it's not a statement
dan1st
dan1st2w ago
I don't think that's intended .
Royalrex25
Royalrex25OP2w ago
fixed it, but I still get the same errors I still have to do the roots after I fix this part
dan1st
dan1st2w ago
I can't tell you what the issue is without seeing the errors my guess is unmatching {}
Royalrex25
Royalrex25OP2w 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
Royalrex25OP2w ago
heres the up to date code
dan1st
dan1st2w ago
if you want me to help you, you need to show me the exact errors
Royalrex25
Royalrex25OP2w ago
I did right here its on the String [] VertexForm line
dan1st
dan1st2w 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
Royalrex25OP2w ago
yeah, I want that string to print out the actual one when running
dan1st
dan1st2w ago
.
Royalrex25
Royalrex25OP2w ago
gives me the "";" expected" and "not a statement" errors
dan1st
dan1st2w ago
on which line?
Royalrex25
Royalrex25OP2w ago
the string VertexForm line
dan1st
dan1st2w ago
How did you change the line now?
Royalrex25
Royalrex25OP2w ago
I copy pasted, and replaced the old string line
dan1st
dan1st2w ago
ah you forgot a + symbol before xVertex
Royalrex25
Royalrex25OP2w ago
that fixed it, I jsut tested the code and somehow the program got -148.25 for the vertex idk how
dan1st
dan1st2w ago
you did vertexFormulaY = A*xVertex*A+B*xVertex+C; That's A^2 x+Bx+C
Royalrex25
Royalrex25OP2w ago
so how do I fix it?
dan1st
dan1st2w ago
read the line and ask yourself why it does that
Royalrex25
Royalrex25OP2w ago
ohh wait, the lack of brackets right?
dan1st
dan1st2w ago
no
Royalrex25
Royalrex25OP2w ago
what else could it be? im honestly at a loss
dan1st
dan1st2w ago
What do you want to do with that line?
Royalrex25
Royalrex25OP2w ago
get the Yvalue of the vertex
dan1st
dan1st2w ago
Using the formula for a parabola. What is the formula for a parabola?
Royalrex25
Royalrex25OP2w ago
y = Ax^2+Bx+C
dan1st
dan1st2w ago
And what's that line doing?
Royalrex25
Royalrex25OP2w ago
squaring A and adding the rest together? I think idk thought it would work
dan1st
dan1st2w ago
Is A squared in this formula?
Royalrex25
Royalrex25OP2w ago
A*x is
dan1st
dan1st2w ago
?
Royalrex25
Royalrex25OP2w ago
ohh, wait so I gotta add brackets then
dan1st
dan1st2w ago
no
Royalrex25
Royalrex25OP2w ago
what else could I do?
dan1st
dan1st2w ago
What is squared in the formula? A*x is not what's squared
Royalrex25
Royalrex25OP2w ago
A is squared? sorry, its been a while
dan1st
dan1st2w 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
Royalrex25OP2w ago
so x is squared then? lol
dan1st
dan1st2w ago
yes - in the formula
Royalrex25
Royalrex25OP2w ago
so I jsut change the 2nd A to an X?
dan1st
dan1st2w ago
hm?
Royalrex25
Royalrex25OP2w 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
dan1st2w ago
maybe
Royalrex25
Royalrex25OP2w ago
maybe? wdym? why "maybe" what would it take for you to help me translate the steps?
dan1st
dan1st2w ago
depends on whether I'm sleeping, whether you are showing what exactly you have an issue with, etc
Royalrex25
Royalrex25OP2w 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
dan1st2w ago
you sue * for the multiplications or do you mean finding the values r and s?
Royalrex25
Royalrex25OP2w 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
dan1st2w ago
the roots which you can get using the abc formula?
Royalrex25
Royalrex25OP2w ago
and the X and Y values for the vertex if needed
dan1st
dan1st2w ago
abc formula?
Royalrex25
Royalrex25OP2w 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
dan1st2w ago
The abc formula is (-b +- sqrt(b^2-4ac))/2a
Royalrex25
Royalrex25OP2w ago
and this would allow me to display the roots?
dan1st
dan1st2w ago
this is the formula for the roots, yes one root with +, one root with -
Royalrex25
Royalrex25OP2w ago
anything specific I need to do to show them?
dan1st
dan1st2w ago
if your task requires anything specific $$ \frac{-b\pm\sqrt{b^2-4ac}}{2a} $$
TeXit
TeXit2w ago
No description
dan1st
dan1st2w ago
^ that formula
Royalrex25
Royalrex25OP2w ago
would needing to print both roots count?
dan1st
dan1st2w ago
Doesn't seem hard
Royalrex25
Royalrex25OP2w ago
and the original formula for the roots gives me "")" or ";" expected", "";" expected", and "not a statement"
dan1st
dan1st2w ago
because the formula isn't valid Java code you have to translate it first
Royalrex25
Royalrex25OP2w ago
how?
dan1st
dan1st2w ago
What do you think?
Royalrex25
Royalrex25OP2w ago
idk lol, im terrible with java and would I need to use two different formulas?
dan1st
dan1st2w ago
yes one with +, one with -
Royalrex25
Royalrex25OP2w ago
ohh, thats what that meant
dan1st
dan1st2w ago
and you can calculate square roots in Java with Math.sqrt(PUT_YOUR_RADICANT_HERE)
Royalrex25
Royalrex25OP2w ago
wait, you mean one with -4ac and one with +4ac right?
dan1st
dan1st2w ago
no there is a +- symbol in the formula Maybe you should first learn how quadratic equations work before implementing it
Royalrex25
Royalrex25OP2w 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
dan1st2w ago
looks about right
Royalrex25
Royalrex25OP2w ago
cool, thanks for all the help with this
JavaBot
JavaBot2w ago
Post Closed
This post has been closed by <@595765455436644367>.
Want results from more Discord servers?
Add your server