02.03.2016 Views

MATLAB by rudra pratap

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8.2 Numeric Versus Symbolic Computation<br />

237<br />

If you find that you want more control over your plots than ezplot gives you,<br />

learn more of <strong>MATLAB</strong>'s plotting features in Lesson 3 of Chapter 2 and in<br />

Chapter 6.<br />

2. A fun tool: funtool. Type funtool and you will be operating a two-screen<br />

plotting calculator that does symbolic calculations. Use this when you need<br />

tu do some quick checking on a function, its derivative, integral, inverse, etc.<br />

The help key explains what the other keys do. Some correspond to basic<br />

MuPAD commands that you can use at the <strong>MATLAB</strong> command line as well.<br />

8.2 Numeric Versus Symbolic Computation<br />

What is the difference between numeric (plain <strong>MATLAB</strong>) and symbolic (the Symbolic<br />

Math Toolbox) computation? Let us say you wanted to know the derivative<br />

of a function, t2 sin(3t114) .<br />

The definition of derivative gives a crude way to numerically calculate the derivative<br />

of a function as f' {f ( x +h) - f ( x)} / h if h is small. The <strong>MATLAB</strong> commands<br />

that follow calculate this approximation of the derivative at a set of points spaced<br />

ilt = h apart.<br />

h =.1 ;<br />

% delta t for the difference<br />

t = -pi : h : pi;<br />

% the region of interest for t<br />

f = t.2.*sin(3*t .(1/4)); % the function at all the t values<br />

fprime = diff (f)/h;<br />

% numerical approx of derivative<br />

% Note : diff (f) has 1 less element than f<br />

plot (t(i:end-1) , fprime) % plot of the derivat ive<br />

The derivative of the function is represented <strong>by</strong> the two lists of numbers t and<br />

fprime. The derivative at t(7) is fprime(7).<br />

Compare this with the Symbolic Math Toolbox calculation of the derivative of<br />

the same function. Here is the command and response.<br />

>> symb_deriv<br />

symb_deriv =<br />

The Symbolic Math Toolbox gives you a formula for the derivative. If you are<br />

patient you can verify <strong>by</strong> hand that indeed<br />

! (t2 sin(3 t114)) = 2 t sin(3 -Yt) + (3/ 4) t514 cos(3 -Yt) .<br />

A plot of the previous function gives about the same curve as the previous numeric<br />

calculation. If you type int (symb_deriv) , you will get back t2*sin(3*t (1/4) )

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!