Ask Your Question
1

Substituting function value in an expression

asked 2011-06-29 23:27:56 +0100

Ondra gravatar image

updated 2011-06-29 23:40:08 +0100

I have an expression like uR(t) == 3*iL(0) + uC(0)/2 - 4

how can I substitute for iL(0) and uC(0), if I'm given, that iL(0) = 0 and uC(0) = 0.

uR, iL, uC are a functions of var t:

t = var('t')
uR = function('uR', t)
iL = function('iL', t)
uC = function('uC', t)

thank you :)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2011-07-01 01:49:26 +0100

benjaminfjones gravatar image

The simplest way is just to use the subs (or substitute) method of your symbolic expression like so:

sage: t = var('t')
sage: uR = function('uR', t)
sage: iL = function('iL', t)
sage: uC = function('uC', t)
sage: 
sage: SE = uR(t) == 3*iL(0) + uC(0)/2 - 4
sage: SE.subs(iL(0)==0)
uR(t) == 1/2*uC(0) - 4
sage: SE.subs(uC(0)==0)
uR(t) == 3*iL(0) - 4
sage: SE
uR(t) == 3*iL(0) + 1/2*uC(0) - 4

You see from the last line that the object SE is not changed during the substitution, so you should assign the result of the substitution. Also, you can do both (or arbitrarily many) substitutions using a dictionary:

sage: R = SE.subs({iL(0):0, uC(0):0})
sage: R
uR(t) == -4
edit flag offensive delete link more

Comments

works, thanks! :), *but* sage gives: __main__:4: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...) Is there an unobsolete way?

Ondra gravatar imageOndra ( 2011-07-01 04:57:49 +0100 )edit

@Ondra: Your original syntax had that problem too. It's hard to see without formatting, so I will put this in an answer, but @benjaminfjones has answered your question :)

kcrisman gravatar imagekcrisman ( 2011-07-01 10:51:43 +0100 )edit
2

answered 2011-07-01 10:53:14 +0100

kcrisman gravatar image

Expanding on my remark:

Functions defined in the way above don't say they have just one variable for input (their expression could, in theory, have some constants like c or a that shouldn't be substituted, only t), so we have to do this:

sage: t = var('t')
sage: uR = function('uR', t).function(t)
sage: iL = function('iL', t).function(t)
sage: uC = function('uC', t).function(t)
sage: SE = uR(t) == 3*iL(0) + uC(0)/2 -4
<no deprecation message>
edit flag offensive delete link more

Comments

thanks a lot! :)

Ondra gravatar imageOndra ( 2011-07-01 11:11:57 +0100 )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

Stats

Asked: 2011-06-29 23:27:56 +0100

Seen: 3,823 times

Last updated: Jul 01 '11