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.Sun, 29 Aug 2021 14:55:38 +0200function vs expressionhttps://ask.sagemath.org/question/58733/function-vs-expression/ Hi there,
Is there a difference between, e.g.,
g=x^2
and
f(x)=x^2
?
In the literature the first is considered to be an expression while the other is a function, but checking their types gives
<class 'sage.symbolic.expression.Expression'>
in both cases.eyalSun, 29 Aug 2021 14:55:38 +0200https://ask.sagemath.org/question/58733/Lazy evaluation of derivatives of an unknown functionhttps://ask.sagemath.org/question/10215/lazy-evaluation-of-derivatives-of-an-unknown-function/Hi,
I am using Sage to check some solutions to partial differential equations. I am wondering if a have an unknown function f, can I somehow form the PDE in terms of its derivatives and then substitute in the assumed solution and evaluate the derivatives after the fact?
Here is what I tried so far:
var('x y')
f = function('f', x, y)
g = derivative(f, x, y)
print(g)
D[0, 1](f)(x, y)
h = D[0, 1](f)(x, y)
print(h)
Traceback (click to the left of this block for traceback)
...
TypeError: 'sage.symbolic.expression.Expression' object has no
attribute '__getitem__'
I figured out that D[0, 1] represents the derivatives with respect to the ith indepent variable of the function (is this a Maxima expression?), but I'm not sure then how to use these types of expressions when I finally want to substitute in the known form of f. I.e., since the output of the expression for g is in terms of D[], and when I try to reuse that expression as h, I get an error (since D is actually some other type of object). Any help would be appreciated. Let me know if my question is not clear.
Many thanks!nosnerosMon, 10 Jun 2013 12:27:40 +0200https://ask.sagemath.org/question/10215/Using matrix elements as argumentshttps://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 10:44:53 +0100https://ask.sagemath.org/question/7774/convert expression to functionhttps://ask.sagemath.org/question/8985/convert-expression-to-function/Hola,
is there a way to convert symbolic expression to proper functions?
E. g. `s = sin(x)` into `x |--> sin(x)`
So far I've been using f(x) = s(x), however, deprection warnings occur:
`DeprecationWarning: Substitution using function-call syntax and unnamed
arguments is deprecated and will be removed from a future release of Sage; you
can use named arguments instead, like EXPR(x=..., y=...)`MathemageSun, 20 May 2012 06:52:44 +0200https://ask.sagemath.org/question/8985/Rewriting an expression in terms of other expressions or functionshttps://ask.sagemath.org/question/8677/rewriting-an-expression-in-terms-of-other-expressions-or-functions/I'd like to know if there is a way to ask Sage to write a given expression in terms of other expressions or functions. The user could have an insight about the latter while the CAS would be stuck. What I want is something like
write(a^2 - b^2, a-b)
write(cos(x+y), (cos(x), sin(x), cos(y), sin(y)))
write(gamma(p+1), gamma(p)) # or any other recurrence relation the user wants to check
Something like directed simplification, but not wholesale.
Green diodSat, 28 Jan 2012 15:42:32 +0100https://ask.sagemath.org/question/8677/Substituting function value in an expressionhttps://ask.sagemath.org/question/8201/substituting-function-value-in-an-expression/I have an expression like `uR(t) == 3*iL(0) + uC(0)/2 - 4`
how can I substitute for `iL(0)` and `uC(0)`, if I'm given, that `iL(0) = 0` and `uC(0) = 0`.
`uR`, `iL`, `uC` are a functions of var `t`:
t = var('t')
uR = function('uR', t)
iL = function('iL', t)
uC = function('uC', t)
thank you :)OndraWed, 29 Jun 2011 23:27:56 +0200https://ask.sagemath.org/question/8201/