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/Evaluate a curl at a point?https://ask.sagemath.org/question/53665/evaluate-a-curl-at-a-point/I'm trying to create a curl example for my calc III students. I figured out how to compute the curl, but not how to evaluate it at a point. Can someone please advise? Thanks, Albert
from sage.manifolds.operators import *
E.<x,y,z> = EuclideanSpace()
v = E.vector_field(exp(x)*sin(y),-exp(x)*cos(y),0, name='v')
show(v.display())
curl_v = curl(v)
show(type(curl_v))
show(curl_v.display())UncountableSetWed, 30 Sep 2020 18:46:55 +0200https://ask.sagemath.org/question/53665/not evaluating expressionhttps://ask.sagemath.org/question/49250/not-evaluating-expression/ var("x",domain=RR)
e =2*x+1
f = 3*x+2
(e+f==e+f).show()
reply: 5x+5=5x+3 of course.
But I would like to have
2x+3+5x+1=5x+3
Is there somethink like e.unevaluate()?
big thanks and happy new year to the whole sagemath communityJingenblSun, 29 Dec 2019 15:13:33 +0100https://ask.sagemath.org/question/49250/evaluating derivative of implicit functionhttps://ask.sagemath.org/question/46026/evaluating-derivative-of-implicit-function/ I am trying to evaluate the derivative of an implicitly defined function
rho = function('rho',u)
u_z_equation = u*z^3 - u*z^2 - z^3 + z^2 - 2*z + 1
implicit = u_z_equation(z=rho)
rho_1 = solve(implicit(u=1),rho(1))[0]
print rho_1
d_rho = solve(diff(implicit,u),diff(rho))[0]
print d_rho(u=1)
But I do not know how to substitute the value I found for rho(1) into the expression for the derivativebrettpimFri, 05 Apr 2019 22:28:44 +0200https://ask.sagemath.org/question/46026/Evaluate button is running forever for a simple code!?https://ask.sagemath.org/question/37724/evaluate-button-is-running-forever-for-a-simple-code/ Hi,
I installed Sage in Arch linux, almost every package and tried it in browser and command line. When I operate a simple code in command line, I get the answer quickly. But when I try same code in browser it just runs and runs without any result. I tried several browser, didn't work in any of them. I need some help.sinaMon, 29 May 2017 02:08:20 +0200https://ask.sagemath.org/question/37724/Does Sage have a plain math expression editor, without any calculation performed?https://ask.sagemath.org/question/35331/does-sage-have-a-plain-math-expression-editor-without-any-calculation-performed/Is there a way to edit an expression in a pretty, classical, math style without declaring variables and without evaluating?
In Mathematica we can write whatever we want using some keystroke shortcuts and it looks just as if it were hand-written. We can keep these notes in a file and re-use them (visualize, modify...) later on. The powerful feature is that we can copy and paste any part of such notes into a notebook and get it evaluated in the most straightforward way.
Can we do this in Sage?
Michel PoquerusseTue, 01 Nov 2016 21:56:19 +0100https://ask.sagemath.org/question/35331/won't evaluate answers given by solve()https://ask.sagemath.org/question/34805/wont-evaluate-answers-given-by-solve/I am solving an equation and then trying to plug in the answers it gives to show that the answers are correct, but sage will not evaluate the answers i plug in.
solve(x^3+1==0,x)
yields
[x == 1/2*I*sqrt(3)*(-1)^(1/3) - 1/2*(-1)^(1/3),
x == -1/2*I*sqrt(3)*(-1)^(1/3) - 1/2*(-1)^(1/3),
x == (-1)^(1/3)]
if you then put into sage `(1/2*I*sqrt(3)*(-1)^(1/3) - 1/2*(-1)^(1/3))^3+1`
the result it gives is `(1/2*I*sqrt(3)*(-1)^(1/3) - 1/2*(-1)^(1/3))^3 + 1`. it's like it doesn't know what to do with it's own answers.akatsukiMon, 12 Sep 2016 22:40:58 +0200https://ask.sagemath.org/question/34805/Evaluate whatever rsolve returns. Recurrence relationshttps://ask.sagemath.org/question/33009/evaluate-whatever-rsolve-returns-recurrence-relations/ sage: from sympy import *
sage: x = Function('x')
sage: n = var('n')
sage: q = rsolve(x(n+1)-(1+(3/(100)))*x(n),x(n),{x(0):10000})
sage: q
10000*(103/100)**n
I want to evaluate the result , say q(5) , but i get the following: ''TypeError: 'Mul' object is not callable''.
Can someone help me
brayn92298Tue, 05 Apr 2016 19:32:34 +0200https://ask.sagemath.org/question/33009/Evaluate a listhttps://ask.sagemath.org/question/32537/evaluate-a-list/Hi,
Suppose for example `E =[x,x^2,x+1]` is a list of elements in `ZZ[x]`. Let `K` be a number field defined in Sage
K.<a> = NumberField(f(x))
for some irreducible polynomial $f(x)$. Then how can one evaluate the list `E` by setting $x=a$ and $x=\sigma(a)$ (conjugate of a) in Sage?
Dianbin BaoThu, 11 Feb 2016 20:57:56 +0100https://ask.sagemath.org/question/32537/Create polynomialhttps://ask.sagemath.org/question/32408/create-polynomial/ Hi all.
I have a set od indexes of varibles and a need to create polynomial which can be evaluated from them. Example:
set = (2), (4), (5), (7,8)
polynomial = x2 + x4 + x5 + x7*x8
And I want to be able to evaluate it like this:
vector = (1, 0, 1, 0, 1, 0, 1, 0)
result = polynomial(*vector)
# result = 0 + 0 + 1 + 1 * 0 = 1
Thank youProMon, 01 Feb 2016 21:55:06 +0100https://ask.sagemath.org/question/32408/Can I deactivate block of cells in worksheet?https://ask.sagemath.org/question/30216/can-i-deactivate-block-of-cells-in-worksheet/I have a worksheet where I first derive a bunch of equation and then use these equations for numerical computations and plotting. If I open the worksheet and want to run a new numerical computation using the same equations, I need to evaluate all the cells at the beginning of the notebook and then I can write my new numerical code and evaluate the new cell. To avoid going through each single cell and pressing Alt+Enter to evaluate, I'd like to use "Evaluate all" from the notebook menu, but this also evaluates all my other numerical cells, which takes an awful long time. Is there a way to 'deactivate' a block of cells in the worksheet, e.g. by turning them into a text block in the worksheet editing environment?
I was thinking about putting <html> before and <\html> after the cells but this did not work. Thanks for your help!stanThu, 22 Oct 2015 13:39:15 +0200https://ask.sagemath.org/question/30216/Shift+Enter and Tab not working in 6.6 with Chrome on OS X 10https://ask.sagemath.org/question/26887/shiftenter-and-tab-not-working-in-66-with-chrome-on-os-x-10/I have a working version 5.11 of sage that I use primarily in the notebook interface together with Chrome. I decided to upgrade to version 6.6. After doing so, I found that the terminal would be running version 6.6 but that the notebook would run version 5.11. I then trashed the 5.11 .app file and the sage folder from my applications folder on OS X 10. After restarting sage, the notebook would open in version 6.6. However, when I opened or created new notebooks, I could not evaluate any cells because Shift+Enter would not evaluate cells. There were no other buttons to evaluate cells either. Additionally Tab would not work as an autocomplete, but rather would move the cursor to other cells and menu tabs.
Any suggestions?Robert BellTue, 19 May 2015 21:12:20 +0200https://ask.sagemath.org/question/26887/Evaluation failhttps://ask.sagemath.org/question/26374/evaluation-fail/hello,
when running "0^0" the result is "1", but when defining "f(x)=0^x" and evaluating "f(0)" the evaluation fails with "ValueError: power::eval(): pow(0,0) is undefined". I guess this one is easy to fix... :)
version: Sage Version 6.5, Release Date: 2015-02-17
regards,
manfreddeadalpsSun, 29 Mar 2015 12:35:31 +0200https://ask.sagemath.org/question/26374/sage 6.5 notebook has no evaluate button after cellshttps://ask.sagemath.org/question/26160/sage-65-notebook-has-no-evaluate-button-after-cells/linux ubuntu 14.04 with kde and unity installed, nvidia drivers
x86-64 6.2 works normally [as does x86-64 6.5 on a different machine with intel drivers and a much closer to a default install]
both of the x86-64 upstream-binary and the download for ubuntu 14.04 don't show the evaluate in the normal location
under the input cell. " Evaluate all" works normally from the menu.
I've tried firefox,chrome browsers under unity.
Any suggestions on conflicts or troubleshooting?dlannomWed, 11 Mar 2015 23:25:17 +0100https://ask.sagemath.org/question/26160/Evaluating symbolic expressionshttps://ask.sagemath.org/question/26076/evaluating-symbolic-expressions/ Hi all,
I have to evaluate in Sage a symbolic expression and, by some constrains of my problem, I have to use a dictionary to do so. Everything goes smooth with symbolic expressions like the following:
var('x,y')
h = x^3+y^3
type(h) #returns sage.symbolic.expression.Expression
h({x:0,y:1}) #returns 1
But, when I use a symbolic expression defined with arguments, it fails:
g(x,y) = x^3+y^3
type(g) #returns also sage.symbolic.expression.Expression
g({x:0,y:1})
And returns "TypeError: no canonical coercion from <type 'dict'> to Callable function ring with arguments (x, y)"
Since both expressions are "sage.symbolic.expression.Expression", why does that occur? Any help would be appreciated.Paco BraxeSun, 08 Mar 2015 19:53:13 +0100https://ask.sagemath.org/question/26076/How to evaluate all cells with one click in cloud.sagemath?https://ask.sagemath.org/question/11031/how-to-evaluate-all-cells-with-one-click-in-cloudsagemath/The Run button evaluates one cell in a row. I've got lots of cells. Is there an analogue of "Evaluate all" button in cloud.sagemath?MasThu, 13 Feb 2014 16:18:02 +0100https://ask.sagemath.org/question/11031/Evaluating values of the Weierstrass $\wp$-functionhttps://ask.sagemath.org/question/10419/evaluating-values-of-the-weierstrass-wp-function/I would like to know how can we evaluate the Weierstrass $\wp$-functions. That is, I would like to find $\wp(\theta,\omega,i\omega)$ for some $\theta,\omega\in\mathbb{R}$.
I'm only able to find a function which outputs the Laurent series of the Weierstrass $\wp$-function when an elliptic curve has been entered. Should I evaluate that laurent series?BlackadderTue, 06 Aug 2013 11:39:19 +0200https://ask.sagemath.org/question/10419/How do I evaluate sum() containing factorial()?https://ask.sagemath.org/question/9937/how-do-i-evaluate-sum-containing-factorial/I am trying to evaluate a sum containing a factorial, but need to do copy and paste of the interim result to get the final answer in the sage notebook (ver. 5.7). Is there a direct way?
var('i k n t')
sum(factorial(3-i)*k^i*t^i, i,0,n)(k=1, n=3, t=4)
> sum(4^i*factorial(-i + 3), i, 0, 3)
If I copy the result into a new input cell and evaluate:
sum(4^i*factorial(-i + 3), i, 0, 3)
only then I obtain the desired
>94
This is annoying, as I would like to compute the result for a long list of n and t and plot the results.
EDIT:
Maybe I simplifed the question too much. Just to specify again why I would like to use symbolics: I actually wanted to evaluate
var('i k n t')
sum(factorial(n-i)*k^i*t^i, i,0,n)
for different values of n and get the symbolic result, e.g. for n = 3, I would expect:
3*k^3*t^3 + 2*k^2*t^2 + k*t
**EDIT2:** Betrema's edited solution is very helpful:
[sum(factorial(n-i)*k^i*t^i, i, 0, n) for n in range(3)]
gives
[1, k*t + 1, k^2*t^2 + k*t + 2]
as desired. **The only remaining question is:
Why does sum(factorial(n-i)*k^i*t^i, i, 0, n)(n=3)
not give k^2*t^2 + k*t + 2?**
Does the .subs() method work differently on symbolic sums than on other symbolic equations?
Thanks again!
stanFri, 22 Mar 2013 17:15:40 +0100https://ask.sagemath.org/question/9937/Evaluate expression with unknownshttps://ask.sagemath.org/question/9816/evaluate-expression-with-unknowns/I'm trying to evaluate an integral that comes out with a crazy long result. I'm not going to paste it here because it really is quite long, which is essentially the problem. The result actually only has a few instances of unknowns in it, 90% of it's length comes from un-evaluated constants (like 2^(1/7), log(11.5), stuff like that). So it sort of looks like:
f(x) = (x* 2* pi* log(5)* 6^1.5) / (3^4*pi^2+x)
except it spans 10 lines.
If I could get sage to just express all of that stuff as a solid number, then the resulting expression wouldn't be so prohibitively long (I think it would actually evaluate out to something similar to the example I gave, number*x/(number+x) ). But numerical_approx() won't take anything with unknowns in it, so I can't just plug that expression into n().
How does one evaluate the knowns in an expression that contains unknowns?
Thank you ahead of time for your help!adamhgMon, 18 Feb 2013 14:59:38 +0100https://ask.sagemath.org/question/9816/open, evaluate, and save a set of worksheets in a single notebookhttps://ask.sagemath.org/question/9311/open-evaluate-and-save-a-set-of-worksheets-in-a-single-notebook/I have a notebook with 25+ worksheets which calculate parameters for shaped NMR pulses. I use an attached .sage file which does most of the calculation. I have updated the .sage file and would like to update the calculations for each worksheet. I would like to automate the following:
1. Open a worksheet
2. Delete all output
3. Evaluate all cells
4. Save the worksheet
5. Close the worksheet
From looking through the documentation it is not how to do this or if it is possible. Any advice on how to do this would greatly appreciated.mhfreyWed, 12 Sep 2012 21:52:12 +0200https://ask.sagemath.org/question/9311/How do I exec a function of N variables.https://ask.sagemath.org/question/9260/how-do-i-exec-a-function-of-n-variables/The python code:
f(x,y)=sin(x) + cos(y) Can be both differentiated and evaluated.
like this:
dfx=diff(f,x);
dfy=diff(f,y)
then evaluated like this:
f(pi/6,pi/9) -> cos(1/9*pi) + 1/2
dfx(pi/6,pi/9) -> 1/2*sqrt(3)
I'm wanting to do something like:
exec("f(t1,t2)=cos(t1)+sin(t2)")
so that I can write an @interact function to define the equations of N variables interactively. When I try the above exec I receive the error: "SyntaxError: can't assign to function call"
I can almost do it, but I'm getting into a horrible inelegant tangle of of eval statements in the process!
Is there a clean way to do it with sage?oldbradTue, 21 Aug 2012 14:49:37 +0200https://ask.sagemath.org/question/9260/IE9: Loss of Sage Functionalityhttps://ask.sagemath.org/question/8284/ie9-loss-of-sage-functionality/I'm using Sage in the high-school second-year Algebra course I teach, and many of my students use Internet Explorer 9.
When I open Sage in IE9, I lose some functionality. Shift-Enter does not evaluate, and "command( + Tab" does not open an options menu. There are probably more problems I haven't seen.
Is there a way to get full Sage functionality in IE9?Brad BurkmanWed, 24 Aug 2011 11:33:23 +0200https://ask.sagemath.org/question/8284/Function value at parametric pathhttps://ask.sagemath.org/question/8897/function-value-at-parametric-path/Hi,
How can I get the value of a 2D function, say f(x,y)=x^3+y^3, along the path determined by a parametric function, say M(x(t)=cos(t),y(t)=sint(t))?
sagembFri, 20 Apr 2012 10:59:08 +0200https://ask.sagemath.org/question/8897/How do I evaluate symbolic expressions numerically in notebook()https://ask.sagemath.org/question/8589/how-do-i-evaluate-symbolic-expressions-numerically-in-notebook/I have solved an equation using this statement
s1 = solve(eq,ss)
The result is
ss = **rhs**
By setting all other variables in the right-hand side of the equation, I can retrieve a value using, among other things,
print **rhs**
or
N(**rhs**),
but when I try
N(ss)
I get the error message "cannot evaluate symbolic expression numerically". How can I evaluate the left-hand side as if it were the right-hand side?
khentiamentiuTue, 10 Jan 2012 19:52:18 +0100https://ask.sagemath.org/question/8589/evaluating an expressionhttps://ask.sagemath.org/question/8470/evaluating-an-expression/Hello,
started to use open source mathematical software. And i have some questions since i can not find in google what i am searching for (maybe i am a bad searcher :S).
The thing is if i write in maple (with predefined F, M, q and Q):
Sum('F[ix]', 'i' = 1 .. n) = 0; '-2*F*cos(45*deg)-3*Q+4*RB*cos(45*deg)-RB*sin(45*deg)-M = 0'; evalf[4](solve(%, RB))
I get
RB := 19.51
And in Sage:
solve(-2*F*cos(45*deg)-3*Q+4*RB*cos(45*deg)-RB*sin(45*deg)-M,RB)
i get:
[23/3*sqrt(2) + 26/3 == 23/3*sqrt(2) + 26/3]
Now i do not find any equivalent to evalf in sage.
Could someone help me, please?JustisMon, 14 Nov 2011 06:59:50 +0100https://ask.sagemath.org/question/8470/converting expressions into latex codehttps://ask.sagemath.org/question/8064/converting-expressions-into-latex-code/latex(
(lim((sin(tan(x))-tan(sin(x)))/x^7,x=0)))
returns the latex code of the answer ie -1/30
but I want the latex code of the limit unevaluated so that I can generate an image of the question from it. How can I do this?ebsSat, 09 Apr 2011 07:36:47 +0200https://ask.sagemath.org/question/8064/Evaluate with a data set?https://ask.sagemath.org/question/7868/evaluate-with-a-data-set/Can sage evaluate an expression with a given data set like ev function in maxima?
For example something like:
A,B = var('A,B')
data = [A==1,B==2]
A + B with data
3
A + B
A + B
Thanks for help.stanislavFri, 14 Jan 2011 11:47:17 +0100https://ask.sagemath.org/question/7868/