Results 1 to 15 of 15
Thread: Help! Plotting a function
 02192009, 09:29 PM #1Member
 Join Date
 Feb 2009
 Posts
 8
 Rep Power
 0
Help! Plotting a function
Can somebody help me plot the function x0 + v0t – gt^2/2, which is the displacement in meters after t seconds when an object is thrown straight up from initial position x0 at velocity v0 meters per second and where g is the constant 9.78033 (gravity).
Using StdDraw, I need to set the x scale to 20 and the y scale to 500.
Any help would be much appreciated. Thanks!
The name of my program is called GravityPlot.
 02202009, 12:05 AM #2Member
 Join Date
 Nov 2008
 Posts
 4
 Rep Power
 0
What is your question?
 02202009, 12:29 AM #3Member
 Join Date
 Feb 2009
 Posts
 8
 Rep Power
 0
Simply put, I do not know how to write the code for it.

Then break down the problem into small steps and solve each small step one at a time. You should this way be able to figure out most of it. Then come on back if you run into trouble with one of the small steps. This way if you come back, you'll be asking a question that can reasonably be answered on the forum. Best of luck.
 02202009, 03:28 AM #5Member
 Join Date
 Feb 2009
 Posts
 8
 Rep Power
 0
I am very new to java and I don't even know how to get the code started.
I don't know how to set the scale of a graph.

then if you are truly lost, you may be beyond our help. Your best bet is to speak to your teacher.
 02202009, 03:56 AM #7Member
 Join Date
 Feb 2009
 Posts
 8
 Rep Power
 0
One reason why I'm asking here is that I can't understand my teacher's explanations so I was thinking of asking someone else to help me understand.

but you've yet to ask a specific question. All you've done is to post the assignment and state that you don't understand it. Please understand that specific questions will bring your specific answers. General unfocused questions will bring you, well, this thread.
 02202009, 04:10 AM #9Member
 Join Date
 Feb 2009
 Posts
 8
 Rep Power
 0
Can someone show me the code on how to plot the function x0 + v0t – gt^2/2 using StdDraw? Also on how to set the x scale to 20 and the y scale to 500?

to change the scale of a set of numbers you simply multiply the numbers by the a scale factor, here it would be 20 for the x axis and 500 for the y axis. There's nothing fancy about that.
To plot a graph an equation is more complex, and as noted above, you have to break the problem down into small problems and solve each small problem.
Steps would include obtaining the data, scaling the data (as noted above), figuring out a range an domain (max and min x and y values).
then if using Swing and Graphics2D, you'd want to create a graphing JPanel where the graphing would take place. If you are unsure how to draw on a JPanel I'd recommend the Sun graphics tutorials at the Sun tutorial site. You'd have to work a bit to learn how to do this, I'm afraid but it's time well spent.
I'm not clear what you mean by "StdDraw" though, and you may need to describe this further as there's nothing with this name in the standard Java library.
 02202009, 04:22 AM #11Member
 Join Date
 Feb 2009
 Posts
 8
 Rep Power
 0
StdDraw is Standard Drawing. I thought this could be done using a normal text editor.

Hm, I've not heard of it, and can't help you much with it. Perhaps others here may know more about this, but I have my doubts. If you have any other information about this and you still need help, please post it here.
 02202009, 05:46 AM #13Member
 Join Date
 Feb 2009
 Posts
 8
 Rep Power
 0
Now I'm just having trouble plotting the data.
double x = Double.parseDouble(args[0]);
double v = Double.parseDouble(args[1]);
double t = Double.parseDouble(args[2]);
double g = 9.78033;
int N = 50;
double[] a = new double[N+1];
for (int i = 0; i <= N; i++)
a[i] = x + v*t  g*(t*t)/2;
StdDraw.setXscale(0, N);
StdDraw.setYscale(10, 500);
for (int i = 1; i <= N; i++)
StdDraw.line(i1, a[i1], i, a[i]);
I'm not even sure if this is the right code to plot the data onto the graph.
 02202009, 06:11 AM #14
I haven't been paying much attetion to this post, but shouldn't the values of x, v t and/or g change ?
Java Code:a[i] = x + v*t  g*(t*t)/2;
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
 02202009, 08:34 AM #15Senior Member
 Join Date
 Sep 2008
 Posts
 564
 Rep Power
 10
Similar Threads

Problems with graph plotting.
By oveeye in forum AWT / SwingReplies: 2Last Post: 02052009, 09:20 AM 
graph plotting
By sirine in forum New To JavaReplies: 5Last Post: 01252009, 04:34 PM 
function
By nanna in forum New To JavaReplies: 1Last Post: 11172008, 10:20 PM 
line plotting math
By Ace_Of_John in forum Java 2DReplies: 1Last Post: 01192008, 11:24 AM 
I want to add function
By romina in forum New To JavaReplies: 1Last Post: 08072007, 06:25 AM
Bookmarks