------------------------------
Problem:

Given a slider x-value find and plot the equation of the line tangent to a given curve f(x) together with the function f(x).

------------------------------

from visual import *
def function():
   print "Type in your function."
   return raw_input("Enter it again, %s." % (yn))

from visual.graph import * # import graphing features
 
funct1 = gcurve(color=color.cyan) # a connected curve object
 
for x in arange(0., 8.1, 0.1): # x goes from 0 to 8

    funct1.plot(pos=(x,5.*cos(2.*x)*exp(-0.2*x))) # plot

from visual.controls import *

# Create "call-back" routines, routines that are called by the interact
# machinery when certain mouse events happen:

s1 = slider(pos=(-15,-40), width=7, length=70, axis=(1,0,0), action=lambda:100) 
s1.value = 70 # update the slider


while True:
    rate(10)
    print str(s1.value)

Is there a way to plot an input function?

Everytime I plot I must type in the function in the pos. Is there a way to ask the user to enter their function and use their function to plot?

Thank you, vegaseat.
Although it did not help me very much, you made a great effort to provide a Python source code library of examples.

For some reason, the line is not on the graph. What are your suggestions?

from visual import *
def printme( str ):
   "This prints a passed string into this function"
   print str;
   return;
# Now you can call printme function
printme("Welcome to program where...");
printme("We'll be able to plot the equation of the line tangent to a given curve together with the function if you provide the equation and the slider x-value.");

eqn = raw_input('Equation in x: ')
x = arange( 0, 10, 0.1 )
curve( x=x, y=eval(eqn) )


from visual.controls import *

# Create "call-back" routines, routines that are called by the interact
# machinery when certain mouse events happen:

s1 = slider(pos=(-15,-40), width=7, length=70, axis=(1,0,0), action=lambda:100) 
s1.value = 70 # update the slider


while True:
    rate(10)
    print str(s1.value)

from visual.graph import * # import graphing features # a graphics curve
    # Set up title/axes labels first
printme = gcurve(color=color.cyan)
for x in arange(0., 10, 0.1):
    printme.plot(pos =(x,eqn,1.0))# Draw the graph on screen
    answer = raw_input("Would you like to print this graph? ")
if answer == "y" or answer == "Y" or answer == "yes":
        g.hardcopy()
This article has been dead for over six months. Start a new discussion instead.