Search code examples
python-3.xsympytaylor-series

How can i replace function's derivation to values?


Function which is include deriative like :

df = -2*x*y(x)*Derivative(y(x), x) - y(x)**2

I have got Derivative(y(x), x)'s value but i don't know how to subs

x= sp.symbols('x  ')
y=sp.Function("y")(x)
f = sp.Function("f")(x,y)

f = -x*y**2

f_num = f.subs([(y,1),(x,2)])

df = sp.diff(f,x)

# I have to calculate df_num value by using(subs) respect 
x,y,Derivative(y(x), x)

thanks everyone who is helping


Solution

  • Does this do what you mean?

    import sympy as sp
    
    x= sp.symbols('x')
    y=sp.Function("y")(x)
    f = sp.Function("f")(x,y)
    
    f = -x*y**2
    
    f_num = f.subs([(y,1),(x,2)])
    
    df = sp.diff(f,x)
    df = df.subs(sp.diff(y,x),1)
    
    sp.pprint(df)