I have tried to solve this through Mathematica but the following code does not give me the result that I want