ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 21 Jun 2021 15:09:34 +0200Incorrect result for integral of (cos z) / zhttps://ask.sagemath.org/question/57637/incorrect-result-for-integral-of-cos-z-z/I am confused by the following result: I'd like to integrate `cos(z) / z` on a circle around the origin. I tried:
var('z,t')
f = (cos(z))/z
show(f)
gamma = e^(i * t)
dg = gamma.diff(t)
h = f(z=gamma) * dg
print(h)
show(h.integrate(t, 0, 2 * pi))
and I get:
I*cos(e^(I*t))
0
If I put the same integral into [WolframAlpha](https://www.wolframalpha.com/input/?i=integral+of+I*cos%28e%5E%28I*t%29%29+from+t+%3D+0+to+2+*+pi), I get the result I was expecting (`2 pi i`).
Is this a bug, or have I specified the problem incorrectly?
ripple_carryMon, 21 Jun 2021 15:09:34 +0200https://ask.sagemath.org/question/57637/matrix is found singular over CC, nonsingular over CDFhttps://ask.sagemath.org/question/56365/matrix-is-found-singular-over-cc-nonsingular-over-cdf/I am trying to take the inverse of complex valued matrix where every entry is either +/-1,+/-i,or 0. The matrices are quite large and I am getting substantial rounding errors when I construct the matrix using "matrix(CDF,array)" and then take the inverse, but I still get an output.
When I construct the matrix using the same array but using "matrix(CC,array)" and then take the inverse I get this error:
ZeroDivisionError: input matrix must be nonsingular
I am confused because the array when I use "matrix(CC,array)" is exactly the same as the array when I use CDF, however "matrix(CDF,array)" is nonsingular and the function inverse works.
Why is this happening and is there another way I can avoid large rounding errors when taking the inverse?
I hope this is enough detail. I'm not really sure how to provide an example of this error occurring since the smallest example of the array I am
working with is still quite large (52x52) and I haven't been able to get this error to occur with smaller simpler arrays.
This is the encoded matrix over the Gaussian Integers - I had been using QQbar() to run it since it worked to get the inverse.
`b = [286102294921876, 178813934326175001, 69849193096160908206250, 27284841053187847167978515625, 10658141036401502788066894531250000, 179100036621093756, 111937522888183596880, 69960951805114746112500, 43725594878196716328140625, 27343048714101314544736328125, 17080310499295592308075000000000, 10675194062059745192527954101562500, 1716613769531255, 112652778625488296880, 44004991650581359960953125, 17189449863508343696746875000000, 63948846218409016728401336669921875, 895500183105468780, 559687614440917984400, 349804759025573730562500, 218627974390983581640703125, 136715243570506572723681640625, 85401552496477961540375000000000, 53375970310298725962639770507812500, 8583068847656275, 563263893127441484400, 85947249317541718483734375000000, 319744231092045083642006683349609375, 4477500915527343900, 2798438072204589922000, 1749023795127868652812500, 1093139871954917907959375000, 683212419971823692323242187500, 427007762482389807701875000000000, 266879851551493629813198852539062500, 42915344238281375, 2816319465637207422000, 1100124791264533997803125000, 429736246587708592418671875000000, 1598721155460225418210033416748046875, 22387504577636719500, 13992190361022949610000, 8745118975639343264062500, 5465699359774589539796875000, 3416062099859118461616210937500, 2135038812411949038509375000000000, 1334399257757468149065994262695312500, 35762786865235000, 13969838619232179688125, 5456968210637569433595703125, 2131628207280300557632452392578125, 1332267629550187848508377075195312500]`
The issue I'm now having is that I expected the inverse this matrix to look much different - as well as the determinant to be much larger.beanplantzThu, 25 Mar 2021 02:03:28 +0100https://ask.sagemath.org/question/56365/Simplifying symbolic complex normhttps://ask.sagemath.org/question/52265/simplifying-symbolic-complex-norm/Sage's simplifier seems to have trouble expanding the square-absolute value of complex numbers:
sage: x,y = var('x,y', domain=RR)
sage: (x^2 + y^2 - abs(x + i*y)^2).simplify_full ()
x^2 + y^2 - abs(x + I*y)^2
How can I ensure sage expands the square-absolute value and simplify this down to zero? I'm aware that using `(x + i*y).norm()` instead of `abs(x + i*y)^2` helps in this particular example, but that solution doesn't generalize. For instance, when I stick expressions involving `x`, `y` into vectors and compute the vector norm, the vector norm is expressed in terms of absolute values, so I still need a way to deal with the `abs`.JunTue, 30 Jun 2020 08:57:16 +0200https://ask.sagemath.org/question/52265/Importing Sage functions into Cython?https://ask.sagemath.org/question/42277/importing-sage-functions-into-cython/ I am trying to define variables in Cython part of my code like this
a,b,c = var('a,b,c')
But in this line I cant import var() function from Sage
from sage.calculus.var import var
I got this error:
$ sage -python real_sage.sage
Compiling ./real_sage.spyx...
Traceback (most recent call last):
File "real_sage.sage", line 6, in <module>
from real_sage import foo
File "real_sage.pyx", line 10, in init real_sage
File "sage/calculus/var.pyx", line 6, in init sage.calculus.var
File "/home/tunamustafakemal/sega/SageMath/local/lib/python2.7/site-packages/sage/symbolic/function_factory.py", line 15, in <module>
from sage.symbolic.function import SymbolicFunction, sfunctions_funcs, \
File "sage/rings/integer.pxd", line 7, in init sage.symbolic.function
File "sage/rings/rational.pxd", line 8, in init sage.rings.integer
File "sage/rings/rational.pyx", line 89, in init sage.rings.rational
File "sage/rings/real_mpfr.pyx", line 1, in init sage.rings.real_mpfr
File "sage/rings/complex_number.pxd", line 6, in init sage.libs.mpmath.utils
File "sage/rings/complex_double.pxd", line 10, in init sage.rings.complex_number
File "sage/rings/complex_double.pyx", line 94, in init sage.rings.complex_double
ImportError: cannot import name complex_number
Thanks for any support.tunaMon, 07 May 2018 06:14:53 +0200https://ask.sagemath.org/question/42277/Complex argument of an algebraic numberhttps://ask.sagemath.org/question/9497/complex-argument-of-an-algebraic-number/This question is closely related to [that question here](http://ask.sagemath.org/question/1945/complex-argument-of-a-symbolic-expression). Basically I'd like to know whether there is a way to compute an *accurate symbolic expression* for the argument of an algebraic number.
That argument will in general not be an algebraic number itself, which seems to cause a lot of headache along the way. The following all fail, sometimes in rather spectacular backtracing ways:
sage: z = QQbar(3 + 2*I)
sage: z.arg()
AttributeError: 'AlgebraicNumber' object has no attribute 'arg'
sage: atan2(imag(z), real(z))
TypeError: Illegal initializer for algebraic number
sage: atan2(SR(imag(z)), SR(real(z)))
TypeError: Illegal initializer for algebraic number
sage: atan2(AA(imag(z)), AA(real(z)))
TypeError: Illegal initializer for algebraic number
I know a few cases which will work.
sage: atan2(QQ(imag(z)), QQ(real(z)))
arctan(2/3)
This however will break if the real or imaginary part were to contain any square roots.
sage: CC(z).arg()
0.588002603547568
This will give me a numeric approximation. I know I can get that approximation to arbitrary precision, but it's still not exact.
I have the impression that `atan2` attempts to turn its result into an algebraic number, which will fail horribly. I would expect that result to contain an unevaluated call to `atan2` instead, for the cases where the argument is not an algebraic number. Can this be done?MvGFri, 02 Nov 2012 12:42:21 +0100https://ask.sagemath.org/question/9497/