1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Maple help

Tags:
  1. Nov 13, 2014 #1
    1. The problem statement, all variables and given/known data
    Using maple cw version, trying to write a state that will compute f=x/y^2 over several iterations.
    y^2 is changing but x is dependent on a value input my user.
    I don't really know how to write the loop?
    I need the loop to run on an interval of different y values that I can put in and then the x value is determined before the loop begins and is fixed, not sure how to put that in either.

    2. Relevant equations
    f=x/y^2

    3. The attempt at a solution
    I guess I would have to use a do loop,
    do x/y^2
    and I would have to declare the x value
    so x=0 for example
    while y -30.5...30.5
    and then answer=f; printed each time

    or something like that
    I'm not really sure on the syntax I haven't used maple before and the online stuff isn't very helpful.
     
  2. jcsd
  3. Nov 13, 2014 #2

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    I am going to try attaching a pdf file of a short Maple session that does some of what you want. I have not attached a file to a PF response before, so I don't know if it will work.

    Hooray, it worked!
     

    Attached Files:

  4. Nov 14, 2014 #3

    Hi!
    Thanks for the reply.
    I am using a different function than x/y^2 but I am getting an error even though I followed the steps you posted.
    Here is my output.


    > Y:=seq(0+.1*(i-1),i=1..570);

    Y := 0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2,

    1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4,

    2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6,

    3.7, 3.8, 3.9, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8,

    4.9, 5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0,

    6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7.0, 7.1, 7.2,

    7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8.0, 8.1, 8.2, 8.3, 8.4,

    8.5, 8.6, 8.7, 8.8, 8.9, 9.0, 9.1, 9.2, 9.3, 9.4, 9.5, 9.6,

    9.7, 9.8, 9.9, 10.0, 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7,

    10.8, 10.9, 11.0, 11.1, 11.2, 11.3, 11.4, 11.5, 11.6, 11.7,

    11.8, 11.9, 12.0, 12.1, 12.2, 12.3, 12.4, 12.5, 12.6, 12.7,

    12.8, 12.9, 13.0, 13.1, 13.2, 13.3, 13.4, 13.5, 13.6, 13.7,

    13.8, 13.9, 14.0, 14.1, 14.2, 14.3, 14.4, 14.5, 14.6, 14.7,

    14.8, 14.9, 15.0, 15.1, 15.2, 15.3, 15.4, 15.5, 15.6, 15.7,

    15.8, 15.9, 16.0, 16.1, 16.2, 16.3, 16.4, 16.5, 16.6, 16.7,

    16.8, 16.9, 17.0, 17.1, 17.2, 17.3, 17.4, 17.5, 17.6, 17.7,

    17.8, 17.9, 18.0, 18.1, 18.2, 18.3, 18.4, 18.5, 18.6, 18.7,

    18.8, 18.9, 19.0, 19.1, 19.2, 19.3, 19.4, 19.5, 19.6, 19.7,

    19.8, 19.9, 20.0, 20.1, 20.2, 20.3, 20.4, 20.5, 20.6, 20.7,

    20.8, 20.9, 21.0, 21.1, 21.2, 21.3, 21.4, 21.5, 21.6, 21.7,

    21.8, 21.9, 22.0, 22.1, 22.2, 22.3, 22.4, 22.5, 22.6, 22.7,

    22.8, 22.9, 23.0, 23.1, 23.2, 23.3, 23.4, 23.5, 23.6, 23.7,

    23.8, 23.9, 24.0, 24.1, 24.2, 24.3, 24.4, 24.5, 24.6, 24.7,

    24.8, 24.9, 25.0, 25.1, 25.2, 25.3, 25.4, 25.5, 25.6, 25.7,

    25.8, 25.9, 26.0, 26.1, 26.2, 26.3, 26.4, 26.5, 26.6, 26.7,

    26.8, 26.9, 27.0, 27.1, 27.2, 27.3, 27.4, 27.5, 27.6, 27.7,

    27.8, 27.9, 28.0, 28.1, 28.2, 28.3, 28.4, 28.5, 28.6, 28.7,

    28.8, 28.9, 29.0, 29.1, 29.2, 29.3, 29.4, 29.5, 29.6, 29.7,

    29.8, 29.9, 30.0, 30.1, 30.2, 30.3, 30.4, 30.5, 30.6, 30.7,

    30.8, 30.9, 31.0, 31.1, 31.2, 31.3, 31.4, 31.5, 31.6, 31.7,

    31.8, 31.9, 32.0, 32.1, 32.2, 32.3, 32.4, 32.5, 32.6, 32.7,

    32.8, 32.9, 33.0, 33.1, 33.2, 33.3, 33.4, 33.5, 33.6, 33.7,

    33.8, 33.9, 34.0, 34.1, 34.2, 34.3, 34.4, 34.5, 34.6, 34.7,

    34.8, 34.9, 35.0, 35.1, 35.2, 35.3, 35.4, 35.5, 35.6, 35.7,

    35.8, 35.9, 36.0, 36.1, 36.2, 36.3, 36.4, 36.5, 36.6, 36.7,

    36.8, 36.9, 37.0, 37.1, 37.2, 37.3, 37.4, 37.5, 37.6, 37.7,

    37.8, 37.9, 38.0, 38.1, 38.2, 38.3, 38.4, 38.5, 38.6, 38.7,

    38.8, 38.9, 39.0, 39.1, 39.2, 39.3, 39.4, 39.5, 39.6, 39.7,

    39.8, 39.9, 40.0, 40.1, 40.2, 40.3, 40.4, 40.5, 40.6, 40.7,

    40.8, 40.9, 41.0, 41.1, 41.2, 41.3, 41.4, 41.5, 41.6, 41.7,

    41.8, 41.9, 42.0, 42.1, 42.2, 42.3, 42.4, 42.5, 42.6, 42.7,

    42.8, 42.9, 43.0, 43.1, 43.2, 43.3, 43.4, 43.5, 43.6, 43.7,

    43.8, 43.9, 44.0, 44.1, 44.2, 44.3, 44.4, 44.5, 44.6, 44.7,

    44.8, 44.9, 45.0, 45.1, 45.2, 45.3, 45.4, 45.5, 45.6, 45.7,

    45.8, 45.9, 46.0, 46.1, 46.2, 46.3, 46.4, 46.5, 46.6, 46.7,

    46.8, 46.9, 47.0, 47.1, 47.2, 47.3, 47.4, 47.5, 47.6, 47.7,

    47.8, 47.9, 48.0, 48.1, 48.2, 48.3, 48.4, 48.5, 48.6, 48.7,

    48.8, 48.9, 49.0, 49.1, 49.2, 49.3, 49.4, 49.5, 49.6, 49.7,

    49.8, 49.9, 50.0, 50.1, 50.2, 50.3, 50.4, 50.5, 50.6, 50.7,

    50.8, 50.9, 51.0, 51.1, 51.2, 51.3, 51.4, 51.5, 51.6, 51.7,

    51.8, 51.9, 52.0, 52.1, 52.2, 52.3, 52.4, 52.5, 52.6, 52.7,

    52.8, 52.9, 53.0, 53.1, 53.2, 53.3, 53.4, 53.5, 53.6, 53.7,

    53.8, 53.9, 54.0, 54.1, 54.2, 54.3, 54.4, 54.5, 54.6, 54.7,

    54.8, 54.9, 55.0, 55.1, 55.2, 55.3, 55.4, 55.5, 55.6, 55.7,

    55.8, 55.9, 56.0, 56.1, 56.2, 56.3, 56.4, 56.5, 56.6, 56.7,

    56.8, 56.9

    > for i from 1 to 570 do
    > if (i=1) then printf("%5s %5s %10s\n", "x", "y", "f(x,y)"):
    > end if:
    > printf("%5.1f %5.1f %10.6f\n", 2.0, Y,f(2.0,Y)):
    > end do:
    x y f(x,y)
    2.0 0.0
    Error, (in fprintf) number expected for floating point format

    > i:='i';

    i := i

    >
     
  5. Nov 14, 2014 #4

    Mark44

    Staff: Mentor

    You haven't defined your function. The second printf statement prints 2.0, then the value for y (0.0), and then fails to print a value for f(2.0, y).
     
  6. Nov 14, 2014 #5

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper


    Look again at your printf statement, and compare it (very carefully) with what I wrote in my little worksheet. See the difference?

    Note: I have tried several time, unsuccessfully, to write exactly what you should do, but for reasons I do not understand the PF server changes my message and refuses to print what I submitted. Therefore, I cannot tell you in detail what the problem is! I can try to sneak around the problem however: Y is an array and can only have a singe (first) element printed. What you want to do is compute and print the single value Y-of-i, etc. (The PF server will not even let me put Y-of-i in symbol form!)
     
  7. Nov 14, 2014 #6

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    In addition to the difficulty outlined in my previous response, the PF system also had me responding to you instead of the OP!
     
  8. Nov 14, 2014 #7

    Mark44

    Staff: Mentor

    The problem is in the bracket notation for arrays. You can write Y[j] but doing so with an index of i, the system thinks you are writing the start tag for italics. Change the index to j or some variable other than i and it will work for you.
     
  9. Nov 14, 2014 #8

    I did it's just above. I didn't include that part of the output because I know I have that done right.
     
  10. Nov 14, 2014 #9

    Mark44

    Staff: Mentor

    Try this, which is similar to what Ray was trying to convey:
    Code (Text):
    for j from 1 to 570 do
    > if (j=1) then printf("%5s %5s %10s\n", "x", "y", "f(x,y)"):
    > end if:
    > printf("%5.1f %5.1f %10.6f\n", 2.0, Y[j],f(2.0,Y[j])):
    >end do:
     
    Note that I changed the loop variable from i to j, because of the way that i inside brackets is displayed here at PF (i.e., as italic). You don't need to change i.
    Also note that in the second printf statement I have Y[j] in two places instead of just Y. The difference is that Y represents the whole array in some form, but what you want is a specific element in the array.

    One other thing. I don't know Maple at all, but if it is anything like C or C++, there's a difference between the = and == operators. The = operator is used for assignment and the == operator is used to determine whether two expressions have the same value. Your 'if (x = 1)' might not be doing what you want it to.
     
  11. Nov 14, 2014 #10

    Hi,
    If I use this I get error unexpected /
    If take the / out it gives the error, error missing operator or ';'
     
  12. Nov 14, 2014 #11

    Mark44

    Staff: Mentor

    Where is there a /? I don't see one at all in the code I provided.
     
  13. Nov 14, 2014 #12
    I got it to work thanks!
     
  14. Nov 14, 2014 #13
    I got it to work thanks!
     
  15. Nov 14, 2014 #14

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    That is good to know. Thanks.
     
  16. Nov 14, 2014 #15

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper


    In Maple, ":=" is the assignment operation, while "=" is either a binary relationship or the signal for an equation, depending on context.
    For example:
    x:=2;
    x := 2
    is(x=2): lprint(%);
    true
    > is(x=1): lprint(%);
    false
    > eq:=y^2=z: lprint(%);
    y^2 = z
    > solve(eq,y): lprint(%);
    z^(1/2), -z^(1/2)
     
    Last edited: Nov 14, 2014
  17. Nov 15, 2014 #16
    Hi,
    If I put in a negative x co-ordinate the it doesn't give me the right output.
    Any ideas on how to fix this?
     
  18. Nov 15, 2014 #17

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    I cannot figure out exactly what your problem is because you have not given us a formula for your function. You must supply more details.
     
  19. Nov 15, 2014 #18
    The formula for the function is arctan((1.82+x)/y) - arctan(x/y)
     
  20. Nov 15, 2014 #19

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    So, this is related to the "skater" problem you described in another thread (provided that the goal is along the x-axis and the skater travels parallel to the y-axis). If x < 0 the skate-line goes through the inside of the goal, so the two angles add instead of subtract. This is also reflected in your formula, because -arctan(x/y) > 0. What is wrong with that?
     
    Last edited: Nov 15, 2014
  21. Nov 15, 2014 #20

    Mark44

    Staff: Mentor

    If you put in a negative x coordinate for what? Please show us the Maple code that you're talking about.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Maple help
  1. Maple command (Replies: 2)

  2. Maple Help. (Replies: 1)

Loading...