Ask Your Question
0

How to recompute symbolic expression

asked 2022-05-18 15:50:54 +0200

ThomasLc gravatar image

I have a symbolic expression with symbolic evaluation.

After I whand to eval the function to it's expression but it doent work :

var("x, omega, t")
u = function('u')(x)

eq = u(x=1) == cos(omega*t)
eq.show()

u(x) = e^(2*t*x)
eq.show

๐‘ข(1)=cos(๐œ”๐‘ก)

๐‘ข(1)=cos(๐œ”๐‘ก)

But now if I create again eq equation, this time it works.

eq2 = u(x=1) == cos(omega*t)
eq2.show()

๐‘’(2๐‘ก)=cos(๐œ”๐‘ก)

Is-it a function recompute to replace easily function by it value ?

The working solution I found isn't practical :

var("x, omega, t")
uf = function('u')(x)

eq = uf(x=1) == cos(omega*t)

eq.show()

u2(x) = e^(2*t*x)

eq.substitute_function(u, u2).show()

I look on subs() and substitute_function() but their behaviour isn't convenient for this case.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-05-18 23:45:30 +0200

Emmanuel Charpentier gravatar image

Possible workaround :

sage: var("x, omega, t");
sage: u=function("u")
sage: def eq():return u(1)==cos(omega*t)
sage: eq()
u(1) == cos(omega*t)
sage: u(x)=e^(2*t*x)
sage: eq()
e^(2*t) == cos(omega*t)

But I fail to see the point...

HTH,

edit flag offensive delete link more

Comments

Yes thank you, this is a convenient solution.

ThomasLc gravatar imageThomasLc ( 2022-05-19 17:10:22 +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

Stats

Asked: 2022-05-18 15:50:54 +0200

Seen: 42 times

Last updated: May 19