From the textbook, I got the answer yp_tb = exp(x)*(tan(x)-x)/2;
From Matlab, I got the answer:
yp_mt = (x*exp(x)*tan(x)^2)/2 - (exp(x)*(2*x - sin(2*x)))/(4*cos(x)^2);
I made the following script to check whether they are same or not.
clear all;
syms x
yp_tb = exp(x)*(tan(x)-x)/2;
yp_mt = (x*exp(x)*tan(x)^2)/2 - (exp(x)*(2*x - sin(2*x)))/(4*cos(x)^2);
% yp_tb = textbook output; yp_mt = matlab output
Equal = isAlways(yp_tb == yp_mt) % Equal is 1, it means they are equal
How to force the MATLAB output to be textbook output?
Adding answer since it worked for the OP.
Use the following code to simplify your equation to the required step:
syms x
yp_tb = exp(x)*(tan(x)-x)/2;
yp_mt = (x*exp(x)*tan(x)^2)/2 - (exp(x)*(2*x - sin(2*x)))/(4*cos(x)^2);
simplify(yp_mt, 3)
Also look at the documentation for simplify