slope field solution for my class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ttja
    New Member
    • Jun 2007
    • 3

    slope field solution for my class

    does anyone know how to create the code for making a slope field? so if i insert a function using gui or something it'll graph the slopes for the function on the graphic screen. here's wat i have so far:

    import math
    from livewires import *
    begin_graphics( )
    x1=random_betwe en(1,639)
    y1=random_betwe en(1,479)
    plot(x1,y1)
    a=5
    while a==5 :
    corner= float(random_be tween(1,3))
    if corner == 1:
    x2=320
    y2=480
    elif corner == 2:
    x2=0
    y2=0
    else:
    x2=640
    y2=0
    x1=(x1+x2)/2
    y1=(y1+y2)/2
    plot(x1,y1)

    i know im missing the yend. and probably some other stuff too, but if anyone can help me out finding the missing codes and errors, i'll appreciate it a lot.
  • ttja
    New Member
    • Jun 2007
    • 3

    #2
    im kinda new to this and i have to make a code for my class

    does anyone know how to create the code for making a slope field? so if i insert a function using gui or something it'll graph the slopes for the function on the graphic screen. here's wat i have so far:
    [CODE=python]
    from livewires import*
    import math
    begin_graphics( )
    def slope(x,y):
    return float(x*y)
    def xend (x,r,m):
    return [r-r/math.sqrt(1+m** 2),x+r/math.sqrt(1+m** 2)]
    def yend (x,r1,m1,r,m)
    return [r-r/math
    r=0.25
    y=4
    while y>=-4:
    x=-4
    while x<=4:
    m=slope(x,y)
    xnd=xend(x,r,m)
    ynd=yend(x,y,xn d[0],xnd[1],m)
    line(50*xnd[0]+200,50*ynd[0]+200,50*xnd[1]+200,50*ynd[1]+200)
    x=x+1
    y=y-1
    [/CODE]
    i know im missing the yend. and probably some other stuff too, but if anyone can help me out finding the missing codes and errors, i'll appreciate it a lot.
    Last edited by bartonc; Jun 17 '07, 01:12 AM. Reason: Added [CODE=python][CODE] tags.

    Comment

    • ttja
      New Member
      • Jun 2007
      • 3

      #3
      slope field tutorial

      how would you go about making a slope field using python?

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        For those interested:
        Given a system of differential equations,
        Code:
            {du}/{dt}=f(t,u,...y,z)
        
                 ...
        
            {dy}/{dt}=j(t,u,...y,z)
            {dz}/{dt}=k(t,u,...y,z)
        the slope field is an array of slope marks in the phase space (the preceding equations imply seven dimensions, but can be any number depending on the number of relevant variables; for example, two in the case of a first-order linear ODE, as seen to the right). Each slope mark is centered at a point (t,u,...y,z) and is parallel to the vector
        Code:
            ( 1 \\ f(t,u,...y,z) \\ ... \\ j(t,u,...y,z) \\ k(t,u,...y,z).
        Much prettier here.

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by ttja
          how would you go about making a slope field using python?
          For solving Differential Equations, you'll probably want to check out the scipy extensions.
          Also, this IEEE Computer Society article looks interesting.

          Comment

          Working...