Results 1 to 15 of 15
  1. #1
    cvubando is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default 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.

  2. #2
    prometheuzz is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default

    What is your question?

  3. #3
    cvubando is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    Simply put, I do not know how to write the code for it.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  5. #5
    cvubando is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    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.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    then if you are truly lost, you may be beyond our help. Your best bet is to speak to your teacher.

  7. #7
    cvubando is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    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.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  9. #9
    cvubando is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    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?

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  11. #11
    cvubando is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    StdDraw is Standard Drawing. I thought this could be done using a normal text editor.

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  13. #13
    cvubando is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    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(i-1, a[i-1], i, a[i]);

    I'm not even sure if this is the right code to plot the data onto the graph.

  14. #14
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    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;
    because if not, you'll be filling the array up with the same value.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  15. #15
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    "t" should be changing. x0, v0 and g should be constants.

    also why are you using this value for gravity? are you using a fictional gravity? i haven't had physics in close to 4 years, but i'm pretty sure that the gravity of earth is 9.81 m/s^2

Similar Threads

  1. Problems with graph plotting.
    By oveeye in forum AWT / Swing
    Replies: 2
    Last Post: 02-05-2009, 09:20 AM
  2. graph plotting
    By sirine in forum New To Java
    Replies: 5
    Last Post: 01-25-2009, 04:34 PM
  3. function
    By nanna in forum New To Java
    Replies: 1
    Last Post: 11-17-2008, 10:20 PM
  4. line plotting math
    By Ace_Of_John in forum Java 2D
    Replies: 1
    Last Post: 01-19-2008, 11:24 AM
  5. I want to add function
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •