ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 09 Oct 2019 06:10:37 -0500generate his own symbolic math functionhttp://ask.sagemath.org/question/48243/generate-his-own-symbolic-math-function/Hi
If I would like to generate my own symbolic math function : **general_falling_factorial(x, j, n)** .
What I should add and modify in the code below ? (I do not know what to do with the two lines below
I know it is ok for the first one, but what must I write for the second one ?)
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
[code on sageCell ](https://sagecell.sagemath.org/?q=iskopi)
j,n=var('j,n')
N=11
show(LatexExpr(r"B_n=\sum_{j=1}^{n+1}\frac{(-1)^{j-1}}{j}{n+1\choose j}\sum_{i=0}^{j-1}(i|j)_n"))
show(LatexExpr(r"\text{with }\, \,(i|j)_n:=i(i-j)\cdots(i-(n-1)j)= \
\text{general_falling_factorial() is not the falling_factorial() SageMath Function} \
\, = \, "),falling_factorial(x, n))
print "https://math.stackexchange.com/questions/497616/is-there-an-explicit-formula-for-the-bernoulli-numbers-that-doesnt-implicitly-r"
print "http://youngp.people.cofc.edu/factbern.pdf"
show(LatexExpr(r"B_n=\sum_{j=1}^{n+1}\frac{(-1)^{j-1}}{j}{n+1\choose j}\sum_{i=0}^{j-1}(i|j)_n"))
show(LatexExpr(r"\text{with }\, \,(i|j)_n:=i(i-j)\cdots(i-(n-1)j)"))
def general_falling_factorial_latex(self, x,j,n):
return '{' + '('+str(x) + ' | ' + str(j) + ')'+'}_{' + str(n) + '}'
general_falling_factorial = function('general_falling_factorial', nargs=3, print_latex_func=general_falling_factorial_latex)
def general_falling_factorial(x, j, n):
r""" to fill up """
from sage.symbolic.expression import Expression
from sage.structure.coerce import py_scalar_to_element
x = py_scalar_to_element(x)
j = py_scalar_to_element(j)
n = py_scalar_to_element(n)
if ((isinstance(j, Integer) or
(isinstance(j, Expression) and
j.is_integer())) and j >= 0) and \
((isinstance(n, Integer) or
(isinstance(n, Expression) and
n.is_integer())) and n >= 0) :
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
def bernoulliExplicit(N) :
bernoulliSL=[]
for n in range(0,N) :
bernoulliSLt=[]
for j in range (1,n+2):
#show("j : ",j)
bernoulliSLt.append((((-1)^(j-1)/j) *(factorial(n+1))/((factorial(j)*(factorial((n+1-j))))))* \
sum([general_falling_factorial(i,j,n) for i in range(0,j)]))
bernoulliSL.append(sum(bernoulliSLt))
return bernoulliSL
show("Explicit Bernoulli List : ",bernoulliExplicit(N))
bernoulliL=[]
for i in range(0,N) :
bernoulliL.append(bernoulli(i))
show("SageMath Bernoulli List : ",bernoulliL)ortolljWed, 09 Oct 2019 06:10:37 -0500http://ask.sagemath.org/question/48243/Substitute expression for function in differential equationhttp://ask.sagemath.org/question/38130/substitute-expression-for-function-in-differential-equation/ This is related to [8293](https://ask.sagemath.org/question/8293/substitute-formal-function-by-an-expression-in-a-differential-equation/), but a lot has changed since then, so I wonder if there is a way to achieve this now.
Expanding on an example from [26114](https://ask.sagemath.org/question/26114/why-is-basic-arithmetic-disallowed-on-symbolic-functions/), I define a differential equation based on unevaluated functions and then want to substitute one of the functions (H) by an expression (T_s^2):
sage: var('T_s')
sage: B = function('B')(T_s)
sage: E = function('E')(T_s)
sage: H = function('H')(T_s)
sage: eq_B_TS = B == H/E
sage: eq1 = diff(eq_B_TS, T_s)
sage: eq1
diff(B(T_s), T_s) == -H(T_s)*diff(E(T_s), T_s)/E(T_s)^2 + diff(H(T_s), T_s)/E(T_s)
sage: eq1.subs(H == T_s^2)
diff(B(T_s), T_s) == -T_s^2*diff(E(T_s), T_s)/E(T_s)^2 + diff(H(T_s), T_s)/E(T_s)
I expected this output:
diff(B(T_s), T_s) == -T_s^2*diff(E(T_s), T_s)/E(T_s)^2 + 2*T_s/E(T_s)
However, the substitution was not carried out inside the differential. Is this a missing feature or a bug? Basically, I would like to be able to formulate general symbolic equations including differentials and integrals, and then insert explicit expressions for the different elements that would allow evaluation of the differentials and integrals. stanThu, 29 Jun 2017 16:12:29 -0500http://ask.sagemath.org/question/38130/A simple problem related to symbolic calculationhttp://ask.sagemath.org/question/26982/a-simple-problem-related-to-symbolic-calculation/Could anyone let me know how you can define a variable as some function of another variable without specific definition? For example, how can you define theta as some function of x and then differentiate the 'sin(theta)' by x?
The following is my code that doesn't work. I couldn't find how to fix it in reference manuals. Any help will be appreciated.
var('theta, y, f')
y=sin(theta) ; theta=f(x);
y.derivative(x)Nownuri1Sat, 30 May 2015 07:15:05 -0500http://ask.sagemath.org/question/26982/Using matrix elements as argumentshttp://ask.sagemath.org/question/7774/using-matrix-elements-as-arguments/I have a rather easy question, or so it would seem. I have looked for an answer but was unable to find one anywhere so I'm asking it here.
I am making a very simple iterative algorithm for which the input as well as the output at the end of every iteration is a vector (or matrix for that matter). What I want to do is use these elements as arguments for several functions during each of the iteration. So for example
x=var('x')
y=var('y')
z=matrix(2,1,[ [1],[1] ]
f=x^2+y^3
H=f.hessian()
Then what I would like to do is say
H(z[0],z[1])
or
H(z)
But no matter what I try I can't seem to get it to work. Ideas?DisneySageFri, 26 Nov 2010 03:44:53 -0600http://ask.sagemath.org/question/7774/automatic substitution within functions?http://ask.sagemath.org/question/7637/automatic-substitution-within-functions/what i do to do this?
sage: var('t w')
sage: f(t) = sin(w*t)
t |--> sin(t*w)
sage: w = 2
sage: f
t |--> sin(2*w)
Without doing f(w=2)!!! imagine that the function is f->f(a,b,c,d,f....,t) like doing this:
...
...
sage: aw1=aw1(m1=1,m2=0.5,l1=1,l2=0.5,g=9.8)
sage: aw2=aw2(m1=1,m2=0.5,l1=1,l2=0.5,g=9.8)
sage: aw4=aw4(m1=1,m2=0.5,l1=1,l2=0.5,g=9.8)
...
...
etc
ngativWed, 25 Aug 2010 12:04:25 -0500http://ask.sagemath.org/question/7637/Is it possible to define (or assume) a general positive function?http://ask.sagemath.org/question/8558/is-it-possible-to-define-or-assume-a-general-positive-function/Hi,
Is it possible to assume a positive function when doing simplifications? (like Simplify[expr,a[t]>0] in Mathematica)
To be explicit, I have
# output: abs(a(t))
# changing to assume(a(t)>0) still doesn't work, and results in a DeprecationWarning
a = function('a',var('t'))
assume(a>0)
sqrt(a**2).simplify_full()
This is to be compared to variable case (where works):
# output: t
assume(t>0)
sqrt(t**2).simplify_full()
I could do a replacement to subs_expr abs(a(t)) into a(t). But is there a simple and elegant resolution? Thank you!
tririverThu, 15 Dec 2011 07:36:40 -0600http://ask.sagemath.org/question/8558/Defining a function and forcing max or min valuehttp://ask.sagemath.org/question/8896/defining-a-function-and-forcing-max-or-min-value/Hi,
Is it possible to define a funtion, say f, and have it be the maximum (or minimum) of another function and a constant?
Example (pseudo-script): if g(x)=log(abs(x)), let f(x)=g(x) if g(x)>0, and f(x)=0 for all g(x)<0
Thanks
N.C.sagembTue, 17 Apr 2012 02:08:11 -0500http://ask.sagemath.org/question/8896/Defining symbolic functions in Sage and importing from Maximahttp://ask.sagemath.org/question/8651/defining-symbolic-functions-in-sage-and-importing-from-maxima/Still following [this thread](http://ask.sagemath.org/question/1077/symbolic-expectations-and-double-integrals), I would like to know how to
1. import in Sage a function defined in Maxima?
In my context, I'm interested in Maxima's pdf_normal so I started to
maxima("load(distrib)");
but how do I proceed from there?<br/>
2. What is the equivalent of Maxima's := symbolic function definition?Green diodSat, 21 Jan 2012 03:44:26 -0600http://ask.sagemath.org/question/8651/How do I get an ordered list of a symbolic functions arguments?http://ask.sagemath.org/question/8462/how-do-i-get-an-ordered-list-of-a-symbolic-functions-arguments/How can I get a list/tuple of the variables in a symbolic function with the same ordering as when the function was defined? e.g. for the function below I would want (z,t) not the alphabetically ordered (t, z) I get with .variables() of .arguments(). The ordering has to be stored/used somewhere in sage because I can differentiate with respect to z and get D[0](u)(z,t) as an answer where the '0' corresponds to 'z'.
sage: var('z,t')
(z, t)
sage: f = function('u',z,t)
sage: print (f)
u(z, t)
sage: f.variables()
(t, z)
sage: f.arguments()
(t, z)
sage: f.diff(z)
D[0](u)(z, t)
sage: f.diff(t)
D[1](u)(z, t)
rtrwalkerThu, 10 Nov 2011 08:41:49 -0600http://ask.sagemath.org/question/8462/Difference between U and U(t)http://ask.sagemath.org/question/8250/difference-between-u-and-ut/If I have
t = var('t')
U = function('U', t).function(t)
what is the difference between the expression *U* and *U(t)*. When should I use which?OndraSat, 30 Jul 2011 13:38:30 -0500http://ask.sagemath.org/question/8250/Difference between f and f(r)http://ask.sagemath.org/question/8123/difference-between-f-and-fr/I was experimenting with symbolic functions, and I was wondering what is the difference between these two forms of creating one:
sage: f1 = function('f', r)
sage: f2(r) = function('f', r)
I have made some experiments [in this Sage worksheet](http://flask.sagenb.org/home/pub/64/), but except for some output differences, I don't know what will happen if I try to differentiate them, integrate them, put them into an equation, etc.
Any ideas?Juanlu001Fri, 20 May 2011 23:14:49 -0500http://ask.sagemath.org/question/8123/