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.Tue, 27 Dec 2016 16:58:06 -0600Variable overrites function defined previouslyhttp://ask.sagemath.org/question/36108/variable-overrites-function-defined-previously/I have u(t) which is an function of t, and g(u) which is a function of u. I want to find the derivative of g(u)*u(t) w.r.t. t.
sage: u(t) = function('u')(t)
sage: h(u) = function('h')(u)
sage: u
u
sage: h
u |--> h(u)
diff(h(u)*u(t),t)
h(u)
This seems to happen because the function u is overwritten when I use u to define the function h. I can get around it this way.
sage: u(t) = function('u')(t)
sage: h(x) = function('h')(x)
sage: u
t |--> u(t)
sage: h
x |--> h(x)
sage: diff(h(u)*u(t),t)
u(t)*D[0](h)(u(t))*D[0](u)(t) + h(u(t))*D[0](u)(t)
Can this be classified as a bug?
If it is, would it be possible to fix it?
Thanks in advance.omoplataTue, 27 Dec 2016 16:58:06 -0600http://ask.sagemath.org/question/36108/Declare variable as function outputhttp://ask.sagemath.org/question/31886/declare-variable-as-function-output/ hello guys,
i wrote a new function, lets call it "func", that has some matrix as input and also some matrix as output.
the thing is, i want to declare the last output of the function as a new variable x ( x=func(A) for a given A) the problem is: if i say
x = func(A)
print x
i get :
none
I guess the problem is, that i calculate more than one thing while the function is running, but at the end i just want to able to use that one single output of the function for further use...bruno171092Mon, 28 Dec 2015 08:32:16 -0600http://ask.sagemath.org/question/31886/Handle variable namehttp://ask.sagemath.org/question/26382/handle-variable-name/Dear all,
I would like to pass a function as a parameter and also one of its variable. The simplest situation would just to evaluate a function f.
def test(f,myvar,myval):
return f(myvar=myval)
f = x^2
print(test(f,x,3)
It returns `x^2`, but I would like `9`. Of course I don't know a priori what would be the name of the variable and f may have several variables.
The long question is that I would like to define something that `plot(f,(x,xmin,xmax))`. Is there's a standard way to handle this triple `(x,xmin,xmax)`? Is there's a web page for the source code for such functions to study the standard implementation?
Thanks a lot!
Arnaud
Arnaud1418Mon, 30 Mar 2015 08:41:21 -0500http://ask.sagemath.org/question/26382/Replace a variable with a functionhttp://ask.sagemath.org/question/23340/replace-a-variable-with-a-function/ Hello i hope anyone can help me with the following problem.
i have the following code
T_w,y,T_m,k_f,rho_f,U_0,h_mstar,R, alpha, delta, Phi = var('T_w y T_m k_f rho_f U_0 h_mstar R alpha delta Phi')
T=T_w+y*(-2*(T_w-T_m)/delta+rho_f*U_0*h_mstar*cos(Phi)/k_f)+y^2*((T_w-T_m)/delta^2-rho_f*U_0*h_mstar*cos(Phi)/(k_f*delta))
u=-6*U_0*R*y*(y-delta)*sin(Phi)/delta^3
integralTu=integrate(T*u,y,0,delta)
now i would like to differentiate integralTu with respect to x (diff(integralTu,x)), but delta must be a function of x (i first defined it as a variable because of the integration).tetraederThu, 10 Jul 2014 07:42:14 -0500http://ask.sagemath.org/question/23340/Why Sage cannot pass a value of variable from one function to another nested function?http://ask.sagemath.org/question/10677/why-sage-cannot-pass-a-value-of-variable-from-one-function-to-another-nested-function/The first i ran this:
sage: f(x)=(2/n)*(sin(n*x)*(-1)^(n+1))
sage: sum(f, n, 1, 2) #using summation function
-sin(2*x) + 2*sin(x)
So, In this case the result was evaluated correctly.
But if i tried to combine the first line and the second line together:
sage: f(x,k) = sum((2/n)*(sin(n*x)*(-1)^(n+1)), n, 1, k)
#where n = 1,2,3 ... k
sage: f(x,2)
-2*sum((-1)^n*sin(n*x)/n, n, 1, 2)
The result wasn't finished!
Why sage cannot evaluate mathematical expression in this case?
Another tried to prove that Sage can pass its variable from left function to right function even though the right function was a nested function:
sage: f(x) = sin(arcsin(x))
sage: f(0.5)
0.500000000000000
Edit:
(See [the same question on SO](http://stackoverflow.com/questions/19711247/why-sage-cannot-pass-a-value-of-variable-from-one-function-to-another-nested-fun).)
terces907Thu, 31 Oct 2013 07:09:56 -0500http://ask.sagemath.org/question/10677/How to magically define variables and use functional notation instead of methodshttp://ask.sagemath.org/question/8127/how-to-magically-define-variables-and-use-functional-notation-instead-of-methods/I am always too lazy to look up again where it is that one can do these things. Not that I would ever use such dangerous things myself.
- Magically define variables (so that you don't have to `var('y')`)
- Magically define functions (so that one doesn't need `boof.annoying_method()`, but instead can do `annoying_method(boof)`)
Once it's on here, people can find it more easily and put themselves in more danger. kcrismanSat, 21 May 2011 16:55:46 -0500http://ask.sagemath.org/question/8127/