Reputation: 325
I have been trying to develop a code in which the user inputs a function using x
and y
which is then read into an integral. I tried using eval
, and sage_eval
but neither worked.
Here is my attempt:
y = var('y')
f(y) = eval(input("What is the function:"))
integral(f(y), y, 0, 16)
Upvotes: 1
Views: 1105
Reputation: 3453
Works for me:
sage: y = var('y')
sage: f(y) = eval(input("What is the function: "))
What is the function: sin(y)
sage: integral(f(y), y, 0, 16)
-cos(16) + 1
Suggestion: read about SageCell, interacts, widgets.
Upvotes: 1