EnlightenedFunky
EnlightenedFunky

Reputation: 325

Input, and reading the input in SageMath

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

Answers (1)

Samuel Lelièvre
Samuel Lelièvre

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

Related Questions