User1961
User1961

Reputation: 131

How to force the MATLAB output in the simple terms?

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?

Upvotes: 1

Views: 70

Answers (1)

ammportal
ammportal

Reputation: 991

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

Upvotes: 1

Related Questions