1

I want to equate those differential equations. I know I can solve them easily in the paper but I want to know how to do it in Python:

from sympy import symbols, Eq, solve
P = Function("P")
Q = Symbol('Q')
Q_d = Symbol("Q_d")
Q_s = Symbol("Q_s")
t = Symbol("t")
dy2 = 3 * Derivative(P(t), t,2)
dy1 = Derivative(P(t), t)
eq1 = Eq(dy2 + dy1 - P(t) + 9,Q_d)
display(eq1)


dy2_ = 5 * Derivative(P(t), t,2)
dy1_ = -Derivative(P(t), t)
eq2 = Eq(dy2_ + dy1_ +4* P(t) -1 ,Q_s)
display(eq2)
−() + /*()+3*2/2 * () + 9 =  
4() − /*()+5*2/2 * () −1 = 

These are basically "supply and demand" equations the result is basically:

2 * 2/2 * () = (2 * /() - 5() +10)

How can I find this result? I know Sympy "Solve" can do such a thing:

solve((eq1,eq2), (x, y))

But in this case, I don't have any knowledge.

Tatanik501
  • 159
  • 10

1 Answers1

3

I assume you get what you call the result by setting Qs = Qd and subtracting the equations? It can be rewritten as

 (2 * /() - 5() +10) - 2 * 2/2 * () = 0

which you can obtain in sympy doing

>>> eq1.lhs - eq2.lhs
-5*P(t) + 2*Derivative(P(t), t) - 2*Derivative(P(t), (t, 2)) + 10

where lhs returns the left-hand side of the equation.

fuenfundachtzig
  • 7,952
  • 13
  • 62
  • 87