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.Thu, 03 Jan 2019 15:21:51 +0100How 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?
Tue, 10 Jan 2012 19:52:18 +0100https://ask.sagemath.org/question/8589/how-do-i-evaluate-symbolic-expressions-numerically-in-notebook/Answer by lionel2000 for <p>I have solved an equation using this statement</p>
<p>s1 = solve(eq,ss)</p>
<p>The result is </p>
<p>ss = <strong>rhs</strong></p>
<p>By setting all other variables in the right-hand side of the equation, I can retrieve a value using, among other things, </p>
<p>print <strong>rhs</strong></p>
<p>or </p>
<p>N(<strong>rhs</strong>),</p>
<p>but when I try </p>
<p>N(ss) </p>
<p>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?</p>
https://ask.sagemath.org/question/8589/how-do-i-evaluate-symbolic-expressions-numerically-in-notebook/?answer=44864#post-id-44864I have got the message:
" cannot evaluate symbolic expression numerically"
This simple example does no problem to sage,
var ('x','y', 'v')
f(x) = exp(-x^2)
x = 10
y = f(v).subs(v=x).numerical_approx(digits=5)
but some more complicate results in the above error message Thu, 03 Jan 2019 15:21:51 +0100https://ask.sagemath.org/question/8589/how-do-i-evaluate-symbolic-expressions-numerically-in-notebook/?answer=44864#post-id-44864Answer by Shashank for <p>I have solved an equation using this statement</p>
<p>s1 = solve(eq,ss)</p>
<p>The result is </p>
<p>ss = <strong>rhs</strong></p>
<p>By setting all other variables in the right-hand side of the equation, I can retrieve a value using, among other things, </p>
<p>print <strong>rhs</strong></p>
<p>or </p>
<p>N(<strong>rhs</strong>),</p>
<p>but when I try </p>
<p>N(ss) </p>
<p>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?</p>
https://ask.sagemath.org/question/8589/how-do-i-evaluate-symbolic-expressions-numerically-in-notebook/?answer=13109#post-id-13109I am not sure why you are trying to print N(ss). ss is just a variable.
Do you want to print s1[0].rhs().n(), which is the solution.Tue, 10 Jan 2012 20:03:07 +0100https://ask.sagemath.org/question/8589/how-do-i-evaluate-symbolic-expressions-numerically-in-notebook/?answer=13109#post-id-13109Answer by khentiamentiu for <p>I have solved an equation using this statement</p>
<p>s1 = solve(eq,ss)</p>
<p>The result is </p>
<p>ss = <strong>rhs</strong></p>
<p>By setting all other variables in the right-hand side of the equation, I can retrieve a value using, among other things, </p>
<p>print <strong>rhs</strong></p>
<p>or </p>
<p>N(<strong>rhs</strong>),</p>
<p>but when I try </p>
<p>N(ss) </p>
<p>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?</p>
https://ask.sagemath.org/question/8589/how-do-i-evaluate-symbolic-expressions-numerically-in-notebook/?answer=13117#post-id-13117I wasn't being clear, so here's some code. Assume that I've already defined an equation eq with a number of terms, including ss. Then I solve the equation for ss, with this result:
s1 = solve(eq,ss)<br>
print s1
Evaluating the above, I see this:
ss == (c\*n\*st^2 + c\*ra\*rtr\*st - ra\*rdt - sqrt(2\*c^2\*n\*ra\*rtr\*st^3 -
2\*c\*ra^2\*rdt\*rtr\*st + ra^2\*rdt^2 + (c^2\*ra^2\*rtr^2 + 2\*c\*n\*ra\*rdis -
2\*c\*n\*ra\*rdr)\*st^2))/(c\*n\*st)
Now I want to calculate the value of ss, given that all the other variables in the equation have been given values, which they have. What I've done until now is copy the entire right-hand side of the equation into a print statement, as follows:
print (c\*n\*st^2 + c\*ra\*rtr\*st - ra\*rdt + sqrt(2\*c^2\*n\*ra\*rtr\*st^3 -
2\*c\*ra^2\*rdt\*rtr\*st + ra^2\*rdt^2 + (c^2\*ra^2\*rtr^2 + 2\*c\*n\*ra\*rdis -
2\*c\*n\*ra\*rdr)\*st^2))/(c\*n\*st)
Evaluating the above, I get a number representing the numeric value of the rhs of the equation, which is also the value of ss.
What I would like to do is have a function that would allow me to do this and get the same result:
print some_function(eq,ss)
because what I really want is the numeric value of ss, assuming that all the other variables in the equation have already been assigned values. And if I should have to modify the equation, I don't want to have to cut and paste a different string of symbols into the print statement. I want to just re-evaluate the lhs of eq.
Thu, 12 Jan 2012 18:32:28 +0100https://ask.sagemath.org/question/8589/how-do-i-evaluate-symbolic-expressions-numerically-in-notebook/?answer=13117#post-id-13117