I would like to maximize the function $U$ with respect to $\theta_0$ in order to find $S_0$.
That's, I want to take derivative the function $U$ with respect to $\theta_0$ in order to find $S_0$.
Which program should I use in order to calculate this derivative ? because it is a bit complicated.
Is it possible to use Matlab for that? Please help me writing Matlab code for this?
Thank you!
(Note: Sorry for not writing the function U directly. But, I hope it is readable.)

It's not a program, but rather a library for a programming language: SymPy for Python. It has a tool for differentiation (as well as integration, limits, etc).
The obvious downside is that you have to be fluent in Python.