Ask Your Question
1

Forcing Symbolic Variables to Always be Real

asked 2015-09-09 06:37:53 +0100

bjem00 gravatar image

I am having a problem, I am trying to do algebra with a function of multiple variables, but Sage is assuming the variables could be complex numbers, which I do not want to do. I have a minimal working example that shows the problem. I am using the method discussed at this Google thread on the issue. I actually want to use the commented out equation, but I can't even get the behaviour right for a purely real (at least conceptually) function.

R, r, L, omega, k, s = var('R r L omega k s')

assume(R, 'real')
assume(r, 'real')
assume(L, 'real')
assume(omega, 'real')
assume(k, 'real')
assume(s, 'real')

R.conjugate().simplify()
r.conjugate().simplify()
L.conjugate().simplify()
omega.conjugate().simplify()
k.conjugate().simplify()
s.conjugate().simplify()

#Z(R,r,L,k,omega,s) = R + I * omega * L + ((s * omega**2 * L**2 * k**2) * (r - I * omega * L)) / (r**2 + omega**2 * s **2 * L**2)
Z(s,L) = s * L

show(Z.diff(s))


Z
show(Z)

(s, L) |--> L*s

(s, L) |--> -(imag_part(L)*D[0](imag_part)(s) - real_part(L)*D[0](real_part)(s))/abs(L*s) + (imag_part(L)*imag_part(s) - real_part(L)*real_part(s))*L/(abs(L*s)*conjugate(L)*conjugate(s))

The derivative of the argument of s*L with respect to s should be zero by definition, since both s and L are purely real variables. Why is Sage assuming the following two things: that real variables all of a sudden become complex, and that s and L are related to each other. I want them to be real independent real variables. Always. How do I 'enforce' this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-09-09 08:17:18 +0100

rws gravatar image

First, with the newest versions of Sage the domain you create a variable with is propagated to the assumption database so you can say:

var('R r L omega k s', domain='real')

I am not sure how you get to the output you give, I got:

sage: Z(s,L) = s * L
sage: Z.diff(s)
(s, L) |--> L
sage: Z
(s, L) |--> L*s
sage: Z(R,r,L,k,omega,s) = R + I * omega * L + ((s * omega**2 * L**2 * k**2) * (r - I * omega * L)) / (r**2 + omega**2 * s **2 * L**2)
sage: Z.diff(s)
(R, r, L, k, omega, s) |--> -2*(-I*L*omega + r)*L^4*k^2*omega^4*s^2/(L^2*omega^2*s^2 + r^2)^2 + (-I*L*omega + r)*L^2*k^2*omega^2/(L^2*omega^2*s^2 + r^2)
sage: Z
(R, r, L, k, omega, s) |--> (-I*L*omega + r)*L^2*k^2*omega^2*s/(L^2*omega^2*s^2 + r^2) + I*L*omega + R

Also, you say that the derivative should be zero. But that's only the case if s is a constant, no?

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: 2015-09-09 06:37:53 +0100

Seen: 1,883 times

Last updated: Sep 09 '15