next up previous
Next: Project The Up: Computer Algebra Previous: Other Features

Final Example

Computer Algebra or Symbolic Computing is particularly useful when a problem involves a large amount of very tedious work where it is easy to miss or lose important terms. One such is the solution of non-linear differential equations using a series expansion. We therefore illustrate such a solution where we are trying to solve the equation
\begin{displaymath}
{\d y\over \d x} = a y^2.
\end{displaymath} (5.1)


In[40]:= y = a0 + a1 x + a2 x^2 + a3 x^3 + a4 x^4
Out[40]= $\displaystyle{a0 + a1\ x + a2\ x^2 + a3\ x^3 + a4\ x^4}$
In[41]:= D[y, x] - a (y)^2
Out[41]= $\displaystyle{a1 + 2\ a2\ x + 3\ a3\ x^2 + 4\ a4\ x^3}$
  $ - a (a0 + a1\ x + a2\ x^2 + a3\ x^3 + a4\ x^4)^2$
In[42]:= equ = Expand[%]
Out[42]= $\displaystyle{-(a\ a0^2) + a1 - 2\ a\ a0\ a1\ x + 2\ a2\ x - a\ a1^2\ x^2 - 2\ a\ a0\ a2\ x^2}$
  $+ 3\ a3\ x^2 - 2\ a\ a1\ a2\ x^3 - 2\ a\ a0\ a3\ x^3 + 4\ a4\ x^3$
  $- a\ a2^2\ x^4 - 2\ a\ a1\ a3\ x^4 - 2\ a\ a0\ a4\ x^4 - 2\ a\ a2\ a3\ x^5$
  $- 2\ a\ a1\ a4\ x^5 - a\ a3^2\ x^6 - 2\ a\ a2\ a4\ x^6 - 2\ a\ a3\ a4\ x^7$
  $- a\ a4^2\ x^8$
In[43]:= equ/.x $\mathrel{-\negthinspace\negthinspace>}$0
Out[43]= $\displaystyle{-(a\ a0)^2 + a1}$
In[44]:= Solve[%==0, a1]
Out[44]= $\displaystyle{\{\{a1\mathrel{-\negthinspace\negthinspace>}a\ a0^2\}\}}$
In[45]:= a1 = a1/.%[[1]]
Out[45]= $\displaystyle{a\ a0^2}$



In[46]:= equ
Out[46]= $\displaystyle{-2\ a^2\ a0^3\ x + 2\ a2\ x - a^3\ a0^4\ x^2 - 2\ a\ a0\ a2\ x^2 + 3\ a3\ x^2}$
  $- 2\ a^2\ a0^2\ a2\ x^3 - 2\ a\ a0\ a3\ x^3 + 4\ a4\ x^3 - a\ a2^2\ x^4$
  $- 2\ a^2\ a0^2\ a3\ x^4 - 2\ a\ a0\ a4\ x^4 - 2\ a\ a2\ a3\ x^5 - 2\ a^2\ a0^2\ a4\ x^5$
  $- a\ a3^2\ x^6 - 2\ a\ a2\ a4\ x^6 - 2\ a\ a3\ a4\ x^7 - a\ a4^2\ x^8$
In[47]:= Coefficient[equ, x]
Out[47]= $\displaystyle{-2\ a^2\ a0^3 + 2\ a2}$
In[48]:= Solve[%==0, a2]
Out[48]= $\displaystyle{\{\{a2\mathrel{-\negthinspace\negthinspace>}a^2\ a0^3\}\} }$
In[49]:= a2 = a2/.%[[1]]
Out[49]= $\displaystyle{a^2\ a0^3}$



In[50]:= equ
Out[50]= $\displaystyle{-3\ a^3\ a0^4\ x^2 + 3\ a3\ x^2 - 2\ a^4\ a0^5\ x^3 - 2\ a\ a0\ a3\ x^3}$
  $+ 4\ a4\ x^3 - a^5\ a0^6\ x^4 - 2\ a^2\ a0^2\ a3\ x^4 - 2\ a\ a0\ a4\ x^4$
  $- 2\ a^3\ a0^3\ a3\ x^5 - 2\ a^2\ a0^2\ a4\ x^5 - a\ a3^2\ x^6 - 2\ a^3\ a0^3\ a4\ x^6$
  $- 2\ a\ a3\ a4\ x^7 - a\ a4^2\ x^8$
In[51]:= Coefficient[equ, x^2]
Out[51]= $\displaystyle{-3\ a^3\ a0^4 + 3\ a3}$
In[52]:= Solve[%==0, a3]
Out[52]= $\displaystyle{\{\{a3\mathrel{-\negthinspace\negthinspace>}a^3\ a0^4\}\} }$
In[53]:= a3 = a3/.%[[1]]
Out[53]= $\displaystyle{a^3\ a0^4}$



In[54]:= equ
Out[54]= $\displaystyle{-4\ a^4\ a0^5\ x^3 + 4\ a4\ x^3 - 3\ a^5\ a0^6\ x^4 - 2\ a\ a0\ a4\ x^4}$
  $- 2\ a^6\ a0^7\ x^5 - 2\ a^2\ a0^2\ a4\ x^5 - a^7\ a0^8\ x^6 - 2\ a^3\ a0^3\ a4\ x^6$
  $- 2\ a^4\ a0^4\ a4\ x^7 - a\ a4^2\ x^8$
In[55]:= Coefficient[equ, x^3]
Out[55]= $\displaystyle{-4\ a^4\ a0^5 + 4\ a4}$
In[56]:= Solve[%==0, a4]
Out[56]= $\displaystyle{\{\{a4\mathrel{-\negthinspace\negthinspace>}a^4\ a0^5\}\} }$
In[57]:= a4 = a4/.%[[1]]
Out[57]= $\displaystyle{a^4\ a0^5}$
In[58]:= y
Out[58]= $\displaystyle{a0 + a\ a0^2\ x + a^2\ a0^3\ x^2 + a^3\ a0^4\ x^3 + a^4\ a0^5\ x^4}$
In[59]:= Factor[%]
Out[59]= $\displaystyle{a0\ (1 + a\ a0\ x + a^2\ a0^2\ x^2 + a^3\ a0^3\ x^3 + a^4\ a0^4\ x^4)}$


This looks like the first few terms of the series for

\begin{displaymath}
y(x) = {a_0\over 1 - a_0 a x}
\end{displaymath} (5.2)

which is indeed the solution of the differential equation (5.1. So we see that in this sort of bookkeeping exercise the use of computer algebra can be of considerable assistance.


next up previous
Next: Project The Up: Computer Algebra Previous: Other Features