Ask Your Question

khentiamentiu's profile - activity

2017-06-05 16:58:39 +0200 received badge  Student (source)
2014-01-20 08:06:44 +0200 received badge  Famous Question (source)
2013-10-16 18:58:48 +0200 received badge  Taxonomist
2013-04-25 11:47:23 +0200 received badge  Notable Question (source)
2012-11-16 09:52:50 +0200 received badge  Popular Question (source)
2012-01-12 18:32:28 +0200 answered a question How do I evaluate symbolic expressions numerically in notebook()

I 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)
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.

2012-01-10 19:52:18 +0200 asked a question 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?