Ask Your Question
1

How to Assign value to a symbolic function?

asked 5 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
0

answered 5 years ago

Emmanuel Charpentier gravatar image

updated 5 years ago

Try:

x.subs?
x.sugstitute_function?

Seasonings to taste...

Preview: (hide)
link

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 ( 5 years ago )

Why can't you use subs? This works:

sage: S(0).subs({P(0,1):100,P(0,0):100})
200
Juanjo gravatar imageJuanjo ( 5 years ago )
0

answered 5 years ago

Juanjo gravatar image

updated 5 years ago

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)
Preview: (hide)
link

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 ( 5 years ago )

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: 5 years ago

Seen: 293 times

Last updated: Dec 13 '19