Ask Your Question
1

How do I evaluate symbolic expressions numerically in notebook()

asked 2012-01-10 19:52:18 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

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?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2012-01-10 20:03:07 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

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

edit flag offensive delete link more
0

answered 2019-01-03 15:21:51 +0200

I 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

edit flag offensive delete link more
0

answered 2012-01-12 18:32:28 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-01-10 19:52:18 +0200

Seen: 3,069 times

Last updated: Jan 12 '12