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, 29 Oct 2021 10:56:21 +0200Assign value to symbolic function?https://ask.sagemath.org/question/59524/assign-value-to-symbolic-function/I have a symbolic function $g(x,y)$, which depends on the variables $x$ and $y$. Using this, I define the function $f(x,y)$ as:
\begin{equation}
f(x,y) = g(x,y) + 2x.
\end{equation}
If I calculate the derivative of $f(x,y)$ with respect to $x$:
\begin{equation}
\frac{df(x,y)}{dx}=\frac{dg(x,y)}{dx}+2.
\end{equation}
Now, I need to evaluate this at $x=0$, knowing that $\frac{dg(x,y)}{dx}\bigg\rvert_{x=0}=10$. This should give me:
\begin{equation}
\frac{df(x,y)}{dx}\bigg\rvert_{x = 0} = \frac{dg(x,y)}{dx}\bigg\rvert_{x = 0} +2=12
\end{equation}
The code I have written to achieve this is the following:
x = var('x')
y = var('y')
g = function('g')(x,y) #symbolic function
f = g + 2*x
der_f = diff(f,x); der_f
and this is what I get:
diff(g(x, y), x) + 2
as I expected. However, I don't know how to follow. In particular, I need to know how to:
1) assign $\frac{dg(x,y)}{dx}\bigg\rvert_{x=0}=10$,
2) evaluate $\frac{df(x,y)}{dx}$ at $x=0$, so that I obtain $\frac{df(x,y)}{dx}\bigg\rvert_{x = 0} = 12$.kekoFri, 29 Oct 2021 10:56:21 +0200https://ask.sagemath.org/question/59524/assign variable valuehttps://ask.sagemath.org/question/35110/assign-variable-value/ Hi!
I'm just getting started with Sage and therefore my question may sound really stupid (and nevertheless I couldn't find an answer here).
I have a matrix with both symbolic entries and numerical values, let's say:
a,b=var('a,b')
M=matrix([[1,a], [0,b]])
Now I want do assign a value to a:
a=0
However if I print M to the screen it still says a in the matrix and not 0.
You can clearly see that I'm really not used to Sage, so what's the problem here?
What should I do if I want to assign a fixed value to a variable which is also used in the calculations where this variable appears?
Thank's for the answers, I know this will sound highly trivial for you!
Philippphilipp7Mon, 10 Oct 2016 20:28:44 +0200https://ask.sagemath.org/question/35110/Assigning variables in a listhttps://ask.sagemath.org/question/27056/assigning-variables-in-a-list/I have a variables list which I use to construct a system of linear equations then I use sage to solve this system. Before I use the solve command I like to equate some of the variables in the list. For example if V is the following list `var('x,y,z,w,a,b,c,d')
V2=[x,y,z,w,a,b,c,d]`
I would like to assign`V[i]=V[7-i] for i in [0..3]`. When I do this I get invalid syntax error. I know that I could easily set x=d, y=c and so on but this is not feasible when the list has too many items in it. Thank you for your help!cihanMon, 08 Jun 2015 21:52:51 +0200https://ask.sagemath.org/question/27056/How do I assign variables from the solution of an equation?https://ask.sagemath.org/question/9572/how-do-i-assign-variables-from-the-solution-of-an-equation/I was pleased to see how easily Sage solves systems of equations. For example, evaluating:
var('A,B')
f(x) = A*x + B
solve([f(3) == 5, f(7) == -3], A, B)
yields:
[[A == -2, B == 11]]
With a little text editing, I can use that solution to define f, which I can then plot or use to solve other equations:
A = -2; B = 11
f(x) = A*x + B
...
Is there a way to make the assignments of A and B (or more directly, f ) from the solution of the linear equations, without the copy+paste+edit step?William H. HooperTue, 27 Nov 2012 09:15:24 +0100https://ask.sagemath.org/question/9572/