You can do exactly what you want in either base MATLAB or using the Symbolic Math Toolbox.
Please search the documentation using the appropriate terms (one of which you use in the title).
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!