Ask Your Question
1

How to Assign value to a symbolic function?

asked 2019-12-12 20:23:39 -0500

JarenK gravatar image

I have the little program:

P = function('P') 
x,y = var('x y')
def S(x): 
    return sum(P(x,y),y,0,1)
S(x)

It returns:

P(x, 1) + P(x, 0)

Now, any idea on how to assign particular values to P(x,y) and return S(x) accordingly?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2019-12-13 06:25:04 -0500

Juanjo gravatar image

updated 2019-12-13 06:26:00 -0500

Just an alternative:

sage: P = function('P')
sage: x,y = var('x,y')
sage: S(x) = sum(P(x,y),y,0,1)
sage: S(2)
P(2, 0) + P(2, 1)
edit flag offensive delete link more

Comments

I want to be able to assign a specific value to P(2,0) and to P(2,1) For instance I would like to be able to set the values: P(2,0)=100 and P(2,1)=100

JarenK gravatar imageJarenK ( 2019-12-13 20:00:44 -0500 )edit
0

answered 2019-12-13 00:12:18 -0500

Emmanuel Charpentier gravatar image

updated 2019-12-13 00:13:29 -0500

Try:

x.subs?
x.sugstitute_function?

Seasonings to taste...

edit flag offensive delete link more

Comments

I am not able to use subs. But yes I would like something as:

P=function('P')
x,y=var('x y')

def S(x):
    return sum(P(x,y),y,0,1)

P(0,1)=100
P(0,0)=100

S(0)
JarenK gravatar imageJarenK ( 2019-12-13 20:01:36 -0500 )edit

Why can't you use subs? This works:

sage: S(0).subs({P(0,1):100,P(0,0):100})
200
Juanjo gravatar imageJuanjo ( 2019-12-15 17:22:07 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-12-12 20:23:39 -0500

Seen: 65 times

Last updated: Dec 13 '19