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.Fri, 31 Mar 2023 19:12:12 +0200Conditional sumhttps://ask.sagemath.org/question/67218/conditional-sum/ I have this data `[income, percentage]`
D=[[1300.0, 0.0476],
[1350.0, 0.142],
[1500.0, 0.142],
[1600.0, 0.0476],
[1700.0, 0.0476],
[1800.0, 0.0476],
[1820.0, 0.0476],
[1900.0, 0.0476],
[2000.0, 0.0952],
[2400.0, 0.0952],
[4500.0, 0.0476],
[4900.0, 0.0952],
[5000.0, 0.0952]]
I would like to calculate the sum of the incomes conditional to the fact that the cumulative percentages is $\leq 40\%$
and the same thing for $\leq 10\%$ starting from the end of the list.
Of course it's not a too complex task but I would like to know if we can do that inside a conditional sum that is a sum conditionned by an an other. I have something like
sum(x[0] for x in D while sum(x[1] for x in D) <= 0.4)
which for obvious reasons cannot work.CyrilleFri, 31 Mar 2023 19:12:12 +0200https://ask.sagemath.org/question/67218/Why desolve() can not solve an ODE while SymPy can?https://ask.sagemath.org/question/64722/why-desolve-can-not-solve-an-ode-while-sympy-can/ For example, in sage, when I call:
x=var('x')
f=function('f')(x)
desolve(f.diff(x)^2+1,f)
It will return:
NotImplementedError: Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.
However, with SymPy, when I call:
x=symbols('x')
f=symbols('f',cls=Function)
dsolve(f(x).diff(x)**2+1,f(x))
It will return the exact result:
[Eq(f(x), C1 - I*x), Eq(f(x), C1 + I*x)]
I know maybe it because sage use Maxima in desolve but not SymPy, however, I consider using both of them and merge the result is a better choice. Or if there already exists a method to use SymPy in sgae?Mr_SpadeTue, 01 Nov 2022 05:22:49 +0100https://ask.sagemath.org/question/64722/Solve an ODE in Sagemath where the the value of the function and the value of its derivative is known at different pointshttps://ask.sagemath.org/question/64490/solve-an-ode-in-sagemath-where-the-the-value-of-the-function-and-the-value-of-its-derivative-is-known-at-different-points/I am new to SageMath (migrating from Mathematica), and I am having trouble solving differential equations where the value of the function and the value of its derivatives are available at different points. As for example,
$$y(x)+y''(x)=x^{2}$$
where, $y(1)=1$ and $y'(2)=1$.
In SageMath, it seems that the boundary conditions needs to be given in the form $[x_0,y_0,x_1,y_1]$ or $[x_0,y_0,{y_0}']$, implying that the value of the function and its derivative needs to be specified at the same point.
Any help on how to solve such equations would be highly appreciated. Thank you!
Kindly note, I am not interested in the actual solution to this problem, but in the Sage implementation of such problems.g117chMon, 17 Oct 2022 21:04:49 +0200https://ask.sagemath.org/question/64490/Derivative With Respect to Functionhttps://ask.sagemath.org/question/61942/derivative-with-respect-to-function/Hi, I have the following problem. Say I have some variable $x$ which depends on $t$. Now let's say I have some function of $x$, say $f(x) = x^2$. Running
t = var('t')
x = function('x', nargs=1)(t)
f = x^2
diff(f, t)
gives me what I would expect, i.e. $2 x\left(t\right) \frac{\partial}{\partial t}x\left(t\right)$. However, if I run
diff(f, x)
I get the error message "TypeError: argument symb must be a symbol". Is there a way for me to differentiate $f$ with respect to $x$ such that it just gives $2x(t)$ as the output?
I hope this question isn't too basic; I'm pretty new to SageMath, but I have spent a decent amount of time trying to solve this issue and have found nothing useful.
RossTue, 12 Apr 2022 18:20:58 +0200https://ask.sagemath.org/question/61942/Sinc functionhttps://ask.sagemath.org/question/23761/sinc-function/I am trying to perform some calculus involving the function $f(x) = \sin(x)/x$ in Sage. This function has a removable sigularity at the origin. Is there a way that I can "modify" the function in Sage to set $f(0) = 1$ while preserving the ability to do things like symbolically differentiate it?ajdWed, 13 Aug 2014 19:57:09 +0200https://ask.sagemath.org/question/23761/Can Sagemath expand integrals on Taylor series?https://ask.sagemath.org/question/60367/can-sagemath-expand-integrals-on-taylor-series/ Hi, many times an integral is too difficult to be solved. Then we can expand it in a Taylor series and take a few terms of the series to approximate it. Can Sagemath do this? If yes, how?cdelvMon, 20 Dec 2021 03:37:09 +0100https://ask.sagemath.org/question/60367/how to replace a symbol with a functionhttps://ask.sagemath.org/question/58802/how-to-replace-a-symbol-with-a-function/ I want to replace the symbol with a function to later take derivatives:
var("L r rdot theta thetadot t e d c G M r_s")
r = function("r")(t)
K2=(1-(rdot**2+r**2*thetadot)/c**2)/(1-rdot/c)**2
eq1=diff(K2,rdot)
eq1
yielding:
-2*rdot/(c^2*(rdot/c - 1)^2) + 2*((thetadot*r(t)^2 + rdot^2)/c^2 - 1)/(c*(rdot/c - 1)^3)
Now, I want to replace rdot, thetadot with derivatives of functions of time.
rdot = function("rdot")(t)
theta = function ('theta')(t)
thetadot=diff(theta,t)
rdot=diff(r,t)
eq2=diff(eq1,t)
I get a result but it is nonsense.
4*thetadot*r(t)*diff(r(t), t)/(c^3*(rdot/c - 1)^3)
How to do this properly?
Thank you
Marco
view(eq2)ny2292000Thu, 02 Sep 2021 15:43:01 +0200https://ask.sagemath.org/question/58802/Implicit derivative at a particular pointhttps://ask.sagemath.org/question/57986/implicit-derivative-at-a-particular-point/ For the function f(x,y) = x^3 + y^3 - 6*x*y, what will be input command in sage math for calculation of dy/dx at (1,2).RGGTue, 13 Jul 2021 07:34:53 +0200https://ask.sagemath.org/question/57986/Please Suggest some references for the concepts of curvature, Radius of curvature by using sagemathhttps://ask.sagemath.org/question/57967/please-suggest-some-references-for-the-concepts-of-curvature-radius-of-curvature-by-using-sagemath/ Please Suggest some references for the concepts of curvature, Radius of curvature by using sagemathRGGMon, 12 Jul 2021 12:16:54 +0200https://ask.sagemath.org/question/57967/A matrix containing differential operators acting on a matrix containing functionshttps://ask.sagemath.org/question/56311/a-matrix-containing-differential-operators-acting-on-a-matrix-containing-functions/Suppose I have a 2x2 operator matrix, D. Some of its elements are of the form (d/dx), and (d2/dx2).
Now when this matrix is multiplied with another matrix, f, whose elements are functions of x, I will get the final matrix whose corresponding elements are differentiated.
for example: **D = matrix([[d/dx, d3/dx3], [d2/dx2, d2/dx2]])** is an operator matrix which operates on a function matrix, **f(x) = matrix([[x, x^2], [x^3, x]])** as D(f(x)) = D*f(x), (simple matrix multiplication).
Writing D = matrix([[diff( , x), diff( , x, 3)], [diff( , x, 2), diff( , x, 2)]]) does not work as diff() function needs an input function.
So how can I write the D() operator matrix?
PS: I could use f.apply_map(lambda e: diff(e, x)), but then it applies d/dx to all elements in f(x). Whereas, I have 'diff()' operators of different orders in the D matrix.ApoorvMon, 22 Mar 2021 13:29:51 +0100https://ask.sagemath.org/question/56311/How do I understand the result of symbolic integralshttps://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/So now I know how to integrate, but when I type in
sage: deriv=diff((exp(x)-1)/x,x); deriv
e^x/x - (e^x - 1)/x^2
sage: deriv.integrate(x)
-1/x + Ei(x) - gamma(-1, -x)
why don't I get back `(exp(x)-1)/x +C `?
Philipp SchneiderWed, 18 Aug 2010 20:04:12 +0200https://ask.sagemath.org/question/7574/Pretty print derivative in Newton notation with dot?https://ask.sagemath.org/question/54975/pretty-print-derivative-in-newton-notation-with-dot/Is there any way to get the pretty printer to produce Newton's notation? - ie. a single dot centred over the variable for first derivative with respect to time, 2 dots for second derivative etc.
Example:
t, y = var('t, y')
x = function('x')(t)
pretty_print(y == 2*diff(diff(x,t),t) - 3 * diff(x,t) + 5)
gives:
![sage math output](https://www.sandyscott.net/wp-content/uploads/2020/12/partialleibniz.png)
but I'd like to see:
![Newton's Notation](https://www.sandyscott.net/wp-content/uploads/2020/12/newton.png)sandy_scottMon, 28 Dec 2020 23:37:51 +0100https://ask.sagemath.org/question/54975/Having trouble in solving two differential equations using desolve_systemhttps://ask.sagemath.org/question/53353/having-trouble-in-solving-two-differential-equations-using-desolve_system/ I am trying to solve the following two differential equations simultaneously:
$$Ma^2\frac{dM}{dr}+(M^2a+6a)\frac{da}{dr}+\frac{1}{r^2}=0$$
$$ar\frac{dM}{dr}+7Mr\frac{da}{dr}+2Ma=0$$
where $M=M(r)$ and $a=a(r)$ are the variables.
I had written the following code in Sage:
sage: r = var('r')
sage: M = function('M')(r)
sage: a = function('a')(r)
sage: de1 = (M*a*a*diff(M,r) + (M*M*a+6*a)*diff(a,r) + 1/(r*r) == 0)
sage: de2 = (a*r*diff(M,r) + 7*M*r*diff(a,r) + 2*M*a == 0)
sage: desolve_system([de1,de2], [M,a])
After writing the above code in Sage, I am getting the following error:
TypeError Traceback (most recent call last)
<ipython-input-26-6bce8159491d> in <module>()
----> 1 desolve_system([de1, de2], [M,a])
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/calculus/desolvers.py in desolve_system(des, vars, ics, ivar)
822 for dvar, ic in zip(dvars, ics[1:]):
823 dvar.atvalue(ivar==ivar_ic, ic)
--> 824 soln = dvars[0].parent().desolve(des, dvars)
825 if str(soln).strip() == 'false':
826 raise NotImplementedError("Maxima was unable to solve this system.")
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/interface.py in __call__(self, *args, **kwds)
606
607 def __call__(self, *args, **kwds):
--> 608 return self._parent.function_call(self._name, list(args), kwds)
609
610 def _sage_doc_(self):
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/interface.py in function_call(self, function, args, kwds)
532 [s.name() for s in args],
533 ['%s=%s'%(key,value.name()) for key, value in kwds.items()])
--> 534 return self.new(s)
535
536 def _function_call_string(self, function, args, kwds):
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/interface.py in new(self, code)
307
308 def new(self, code):
--> 309 return self(code)
310
311 ###################################################################
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/interface.py in __call__(self, x, name)
242
243 if isinstance(x, six.string_types):
--> 244 return cls(self, x, name=name)
245 try:
246 return self._coerce_from_special_method(x)
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
670 self._name = parent._create(value, name=name)
671 except (TypeError, RuntimeError, ValueError) as x:
--> 672 raise TypeError(x)
673
674 def _latex_(self):
TypeError: ECL says: Error executing code in Maxima: desolve: can't handle this case.
Can someone help me with the problem. I am new to Sage and so I could not interpret the error.
Thanks in advance!Abby11Mon, 07 Sep 2020 13:20:52 +0200https://ask.sagemath.org/question/53353/I'm searching to perform this multivariate limit (correctly)https://ask.sagemath.org/question/53309/im-searching-to-perform-this-multivariate-limit-correctly/ I'm searching to perform this kind of limit (without restricting and executing the limit to a variable):
$$
\lim_{(x, y)\to(0, 0)}\frac{x^3y}{x^6+y^2}
$$
In the documentation I didn't find a multivariate limit function..Teo7Sat, 05 Sep 2020 11:14:41 +0200https://ask.sagemath.org/question/53309/Error in integralhttps://ask.sagemath.org/question/53172/error-in-integral/I've got this error on the second integral. I put the code on wxMaxima and returned sucessfull. On wxMaxima, raise a question "z is positive, negative or zero?", also on sage, but on sage I can't answer that. How can I correct this?
```x,y,z = var("x y z")```
```function = x*e^(-y)```
``` integral(function,y,0,ln(x)).integral(x,0,2*z) ```gabrielromao5Tue, 25 Aug 2020 15:50:58 +0200https://ask.sagemath.org/question/53172/Unexpected result in calculating limitshttps://ask.sagemath.org/question/50767/unexpected-result-in-calculating-limits/Limit of `sqrt(x-3)` when `x` approaches `3` doesn't exist but the sage returns `0`. Why is that?
sage:
sage: limit(sqrt(x-3), x=3)
0
sage:
ggWed, 15 Apr 2020 13:43:24 +0200https://ask.sagemath.org/question/50767/Sage returning wrong derivativehttps://ask.sagemath.org/question/50704/sage-returning-wrong-derivative/I am trying to calculate the derivative of `y = e^(x*y)`
Hand calculation give me the result of `dy/dx = ( y*e^(x*y) ) / ( 1 - x*e^(x*y) )`
But the sage is giving me the wrong output of `-y/x`. Here is my code:
sage:
sage: y=function('y')(x)
sage: y
y(x)
sage:
sage: expr = exp(1)**(x*y)
sage:
sage: diff(y)
diff(y(x), x)
sage:
sage: diff(expr)
(x*diff(y(x), x) + y(x))*e^(x*y(x))
sage:
sage: solve(diff(expr), diff(y))
[diff(y(x), x) == -y(x)/x]
sage:
sage:
ggSun, 12 Apr 2020 19:25:28 +0200https://ask.sagemath.org/question/50704/How are symbolic derivatives composed in quaternions?https://ask.sagemath.org/question/49785/how-are-symbolic-derivatives-composed-in-quaternions/The scripts below were run in: Sage Cell Server, version: 'SageMath version 9.0, Release Date: 2020-01-01'
I am a new user of SageMath. I have previously used math packages, but SageMath is above and beyond all I have encountered before. It also has remarkably comprehensive documentation. In particular I have found Vector calculus with SageMath and Sage Reference Manual: Quaternion Algebras (insufficient karma to post links). I note that the latter is dated Jan 01, 2020. The examples below are drawn from those two sources. I am searching for calculus tools in the quaternion algebra package. I want to do something like this, which works in EuclideanSpace:
Sage: %display latex
Sage: from sage.manifolds.operators import *
Sage: E.<x,y,z> = EuclideanSpace()
Sage: F = E.scalar_field(function('f')(x,y,z), name='F')
Sage: grad(F).display()
grad(F) = d(f)/dx e_x + d(f)/dy e_y + d(f)/dz e_z The EucliedanSpace also knows how to pretty-print it with LaTeX.
This is as close as I have gotten with quaternions:
Sage: N.<a,b,c,d,y> = QQ[]
Sage: Q.<i,j,k> = QuaternionAlgebra(SR,-1,-1)
Sage: def qd(u):
Sage: w = j*(diff(u[0],y) + diff(u[1],y)*i + diff(u[2],y)*j + diff(u[3],y)*k)
Sage: return w
Sage: b = sin(y)
Sage: f = a+b*i+c*j+d*k
Sage: t = qd(f)
Sage: show(t)
(-cos(y))*k
This is the correct quaternion result, but I want to change the declaration of "b" so that I get something like
**(-d(f)/dy) * k**. Here are the problems that concern me.
1. "diff" does not correctly handle "f" as an argument. It returns 0.
2. The definition in the function "qd" (quaternion derivative) of w should contain 3 more rows, but this one is enough to illustrate my main issue: If "b" is not defined as a specific function (e.g. sin(y)), "diff" returns 0. I would like it to return the derivative display formula, as the Euclidean example does.
3. Replacing show(t) with t.display() returns error messages such as "object has no attribute 'blah_blah'" and "raise AttributeError(dummy_error_message)." There may still be some work in progress here.
I hope there is presently a solution within SageMath. Please adapt the second script or give me an example script.
If not, I am reasonably competent with Python 3. If someone can give me links to the relevant source for the EuclideanSpace methods of "grad" and "function" and to the QuaternionAlgebra source for "diff," I may be able to add a method or two to the QuaternionAlgebra implementation and advance the development of that part of the system, or at least register myself as a beta-tester.
Thanks very much for any help you can give me!
quirkyTue, 04 Feb 2020 20:31:21 +0100https://ask.sagemath.org/question/49785/symbolic differentiation of unknown functionhttps://ask.sagemath.org/question/49362/symbolic-differentiation-of-unknown-function/I want to do some formal calculus with unknown functions
for the purpose of solving differential equations.
Say `F(t) = v(t)*t^2`, where `v` is an unknown differentiable function.
Then I would like to declare `v` as such and be able to get
`F.diff(t) = 2*t*v+t^2*v.diff(t)`
It is similar to [Ask Sage question 8822](https://ask.sagemath.org/question/8822)
but the solution does not seem to work anymore, as `function()` takes
only one argument and not 2 as in the description.
Anyone know what the syntax is in 8.9? Or in 9.0, when that becomes available?asgerSat, 04 Jan 2020 21:10:03 +0100https://ask.sagemath.org/question/49362/Is there any way to define an as-yet-unknown function?https://ask.sagemath.org/question/8822/is-there-any-way-to-define-an-as-yet-unknown-function/I'd like to know if there's a way of declaring functions in sage that are as-yet unknown. For example, let's say I have a function
p = R*T/v - a(T)/v/(v+b)
And I would like to be able to take a derivative like this
deriv(p,T)
and be given something back a partial derivative something like
R/v - diff(a(T),T)/v/(v+b)
However at present I can't seem to put an abstract function `a(T)` into my expression or find anything in the documentation that says how this is done.
As I recall there was a way to do this with wxMaxima, so maybe I just haven't found the trick in Sage yet.
jdpipeFri, 23 Mar 2012 14:11:38 +0100https://ask.sagemath.org/question/8822/Solve failshttps://ask.sagemath.org/question/48390/solve-fails/I wonder why the Variable 'x_0' not found
gr=Polyhedron(ieqs=[(10,-1,0),(-12,0,1)])
p1=gr.plot()
x_0, x_1 = var('x_0 x_1')
lin=solve([70==6*x_0+18*x_1],x_1)
p2=plot(lin, (x,8,14))
p1+p2CyrilleFri, 18 Oct 2019 06:50:09 +0200https://ask.sagemath.org/question/48390/how do I enter 2sin|1−3√2|cos|1+ 2√3|https://ask.sagemath.org/question/47722/how-do-i-enter-2sin1-32cos1-23/when I enter it in SageMath as `2 * sin * abs(1-3 * sqrt(2))*cos*abs(1+2 * sqrt(3))` it does not run the code? your help would be very appreciated :)ariaaaaaaaaMon, 02 Sep 2019 17:44:08 +0200https://ask.sagemath.org/question/47722/error for (3*e+2*I)*(-3+pi*I)https://ask.sagemath.org/question/47729/error-for-3e2i-3pii/so, I have to type in the problem (3e+2i)(−3+πi)...I enter in `(3*e+2*I)*(-3+pi*I)` on SageMath but come up with the answer, -30.74772176 + 19.61920267*I....am I dumb or is the correct answer?ariaaaaaaaaMon, 02 Sep 2019 19:07:52 +0200https://ask.sagemath.org/question/47729/how do I enter (3e+2i)(−3+πi)?https://ask.sagemath.org/question/47715/how-do-i-enter-3e2i-3pi/every time I enter I to represent i, it comes as an invalid syntax? pls help :)ariaaaaaaaaMon, 02 Sep 2019 00:10:09 +0200https://ask.sagemath.org/question/47715/how do I enter (3e+2i)(−3+πi)?https://ask.sagemath.org/question/47714/how-do-i-enter-3e2i-3pi/ every time I enter i as I it comes up as an invalid syntax? Pls help ariaaaaaaaaMon, 02 Sep 2019 00:09:14 +0200https://ask.sagemath.org/question/47714/Computing a formula in SAGEhttps://ask.sagemath.org/question/47509/computing-a-formula-in-sage/Fix the positive integer numbers $t_1, t_2, t_3,t_4, t_5.$ We have the following formula:
$$ S= \sum_{i, j, h, m, k_1 + k_2+k_3+k_4 = i-t_1, \ell_1+\ell_2 + \ell_3 = j -t_2 + k_4, u_1 + u_2 = h - t_3+k_3+\ell_3 }M_1.M_2.M_3. M_4,$$
where
$$ M_1 = \binom{t_5-k_1}{k_1}\binom{t_4-k_2}{k_2}\binom{t_3-k_3}{k_3}\binom{t_2-k_4}{k_4}$$
$$ M_2 = \binom{t_5-k_1-\ell_1}{\ell_1}\binom{t_4-k_2-\ell_2}{\ell_2}\binom{t_3-k_3-\ell_3}{\ell_3}$$
$$ M_3 = \binom{t_5-k_1-\ell_1-u_1}{u_1}\binom{t_4-k_2-\ell_2-u_2}{u_2};$$
$$ M_4=\binom{t_1+t_2+t_3+t_4 +t_5-i - j-h-m}{m - t_4 + k_2+ \ell_2 + u_2}.\lambda_i\lambda_j\lambda_h\lambda_m\lambda_{t_1+t_2 + t_3+t_4+t_5 - i - j-h-m}$$
Here, the binomial factors $\binom{n}{k}$ mod 2 and the value of $S$ mod 2. By convention, $\binom{n}{k} \equiv 0$ (mod 2) if either $k < 0$ or $n < 0$ or $k > n.$
I don't how to construct this formula in SAGE. Can someone show me how to compute it using SAGE?VochauMon, 19 Aug 2019 15:27:56 +0200https://ask.sagemath.org/question/47509/Calculating Cauchy Integrals in Sagehttps://ask.sagemath.org/question/47017/calculating-cauchy-integrals-in-sage/Hi!
I am relatively new to complex analysis and I am trying to write down the following integral in Sage Math:
$$
I(k) = \frac{1}{2i\pi}\oint\frac{(1-t^2)}{(1-t)^n}\frac{dt}{t^{k+1}}
$$
from a paper that can be found at:
http://magali.bardet.free.fr/Publis/ltx43BF.pdf
The contour is a unit circle around the origin with a radius less than 1.
whereby $$S(n) = \frac{(1-t^2)}{(1-t)^n} $$ is a formal power series. The Cauchy Integral will produce the k-th coefficient of $S(n)$. I tried doing the following:
<!-- language: python -->
def deg_reg_Cauchy(k, n, m):
R.<t> = PowerSeriesRing(CC, 't')
constant_term = 1/(2*I*pi)
s = (1-t**2)**m / (t**(k+1)*(1-t)**n)
s1 = constant_term * s.integral()
return s1
I realize this is probably ***very*** wrong and I used $0$ till $2\pi$ as simple placeholders until I find appropriate values. Does anyone have any tips on how to go about this, please? Below is the error message that is being outputted by Sage.
<!-- language: python -->
ArithmeticError: The integral of is not a Laurent series, since t^-1 has nonzero coefficient.
Thank you!JoaoDDuarteSat, 29 Jun 2019 19:01:11 +0200https://ask.sagemath.org/question/47017/2D Points, best paractive to store Pointshttps://ask.sagemath.org/question/45444/2d-points-best-paractive-to-store-points/
sage: from sage.plot.point import Point
sage: P = Point([1,2],[2,3],{'alpha':.5})
sage: P
Point set defined by 2 point(s)
sage: P.options()['alpha']
0.500000000000000
sage: P.xdata
[1, 2]
Why is this not working:
sage: P = Point([1,2],[2,3])
Why do I need this alpha Parameter?
thethaWed, 13 Feb 2019 11:33:40 +0100https://ask.sagemath.org/question/45444/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/Is matrix calculus possible within sagemath?https://ask.sagemath.org/question/32414/is-matrix-calculus-possible-within-sagemath/For example, is it possible to compute the following partial derivative in Sagemath:
$$
A_{ij} = \frac{\partial e_{ij}(x)}{\partial x_i} = \begin{pmatrix}
-R_{ij}^T R_i^T & R_{ij}^T \frac{\partial R_i^T}{\partial \theta_i} (t_j - t_i) \\\
0^T & -1
\end{pmatrix}
$$
for
$$
e_{ij}(x) = \begin{pmatrix}
R_{ij}^T (R_i^T (t_j - t_i) - t_{ij}) \\\
\theta_j - \theta_i - \theta_{ij}
\end{pmatrix}
$$
and
$$
x_i^T = (t_i^T, \theta_i)
$$
$$
z_{ij}^T = (t_{ij}^T, \theta_{ij})
$$
The background shouldn't be important, but just for completeness: this example is an excerpt from Robotics, especially the problem of Pose Graph Simultaneous Mapping and Localization. $x_i$ defines a pose in $\mathbb{R}^2$ with translation $t_i$ and rotation angle $\theta_i$, $z_{ij}$ defines a transform between two poses and $e_{ij}(x)$ defines the error between two poses, i.e. a transform between them.
morphTue, 02 Feb 2016 10:20:41 +0100https://ask.sagemath.org/question/32414/