Ask Your Question
1

How to Assign value to a symbolic function?

asked 2019-12-13 03:23:39 +0200

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 07:12:18 +0200

Emmanuel Charpentier gravatar image

updated 2019-12-13 07:13:29 +0200

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-14 03:01:36 +0200 )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-16 00:22:07 +0200 )edit
0

answered 2019-12-13 13:25:04 +0200

Juanjo gravatar image

updated 2019-12-13 13:26:00 +0200

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-14 03:00:44 +0200 )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-13 03:23:39 +0200

Seen: 221 times

Last updated: Dec 13 '19