Ask Your Question

bjem00's profile - activity

2021-02-03 15:30:25 +0200 received badge  Student (source)
2020-09-04 10:18:30 +0200 received badge  Famous Question (source)
2018-05-25 01:54:14 +0200 received badge  Notable Question (source)
2016-12-12 16:46:59 +0200 received badge  Popular Question (source)
2015-09-09 06:37:53 +0200 asked a question Forcing Symbolic Variables to Always be Real

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?