Problem with using "subs"

28 views
Skip to first unread message

Zing

unread,
Jul 1, 2017, 8:26:12 AM7/1/17
to sympy
Hi,

I am not able to do substitution of one expression into another. Can anyone tell me why. The last line of the code is throwing an error.

Thanks.

Ankur Sinha

P.S. I posted this message a while ago but am not able to see it in the topics. Apologies if this attempt leads to two posts.

from IPython.display import display, Math
from sympy import *

#Production
x = symbols('x')
#Tax
t = symbols('t')
#Level of automation (varies between 0 and 1)
l = symbols('l')

#Parameters
a,b,c,d,e,f,g,h = symbols('a b c d e f g h')
k,m,alpha = symbols('k m alpha')

#Solving firm's problem with automation tax
priceF = a - b*x
#Cost without automation
costWoutAutomation = d*x**2 + e*x + f

#Firm's profit
profitF = (1-alpha)*(priceF*x - costWoutAutomation)

#Solving
foc_x = diff(profitF,x)
optimal_x = solve(foc_x,x)

print(optimal_x)

print(optimal_x.subs(x,k))

Aaron Meurer

unread,
Jul 1, 2017, 10:49:12 PM7/1/17
to sy...@googlegroups.com
solve returns a list, so you need to use optimal_x[0] to get the first element.

But anyway, since you are solving for x, the result from solve does
not contain x, so the subs would do nothing.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/7fe6b265-dc97-401f-aefc-86419c04164b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Zing

unread,
Jul 2, 2017, 3:14:15 AM7/2/17
to sympy
 >>solve returns a list, so you need to use optimal_x[0] to get the first element.

Thanks a lot Aaron. This was helpful.
Reply all
Reply to author
Forward
0 new messages