Ask Your Question
1

Multiply symbolic function by number or expression

asked 2021-11-19 19:51:33 +0200

vejtics gravatar image

I want to define a symbolic function in terms of other symbolic functions, like so:

function('psi psi_1 psi_2')
psi = 1/sqrt(2) * (psi_1 + psi_2 * i)

When running the code, I get the error:

TypeError: unsupported operand type(s) for *: 'NewSymbolicFunction' and 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_gaussian'

The same error appears when I replace i with a real number.

Is there any fundamental mistake I'm making? If so, what should I do instead? If not, is there a workaround?

The reason I am defining a function like this is because I need to find the derivative of the psi function in terms of derivatives of the latter two functions.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-11-20 10:02:57 +0200

tmonteil gravatar image

updated 2021-11-20 12:11:48 +0200

psi_1 and psi_2 are kind of not completely defined (in particular, they are not member of the symbolic ring, hence they can not benefit from the coercions between the symbolic ring and other rings), for example at this stage it is not clear how many symbolic variable do they use, see:

sage: parent(psi_1)
<class 'sage.symbolic.function_factory.function_factory.<locals>.NewSymbolicFunction'>

sage: psi_1(x)
psi_1(x)
sage: var('y')
y
sage: psi_1(x,y)
psi_1(x, y)

sage: parent(psi_1(x))
Symbolic Ring

If you decide that those are function of a single variable, it works:

sage: psi = 1/sqrt(2) * (psi_1(x) + psi_2(x) * i)
sage: psi
1/2*sqrt(2)*(psi_1(x) + I*psi_2(x))
edit flag offensive delete link more
1

answered 2021-11-19 23:37:20 +0200

slelievre gravatar image

updated 2021-11-19 23:39:09 +0200

No need to include psi in your initial function declaration, as you then define psi in the next line.

Not sure how to explain the error you get, but here is something that works:

sage: psi1, psi2 = function('psi_1, psi_2')
sage: psi(t) = 1/sqrt(2) * (psi_1(t) + psi_2(t) * i)

That defines psi as a function. Observe the result:

sage: psi
t |--> 1/2*sqrt(2)*(psi_1(t) + I*psi_2(t))

That function can be differentiated:

sage: diff(psi)
t |--> 1/2*sqrt(2)*(diff(psi_1(t), t) + I*diff(psi_2(t), t))

sage: diff(psi(t), t)
1/2*sqrt(2)*(diff(psi_1(t), t) + I*diff(psi_2(t), t))
edit flag offensive delete link more

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: 2021-11-19 19:51:33 +0200

Seen: 239 times

Last updated: Nov 20 '21