Published online by Cambridge University Press: 08 February 2010
In this chapter we shall use MATLAB to draw graphs of functions y: = f(x), to approximate functions in two different ways as polynomials, to solve equations f(x) = 0 and to draw systems of lines in the plane forming an ‘envelope’. (For graphs z = f(x,y), see Chapter 17.) The technique of approximation is particularly important in applications, where it is desirable to replace a relatively complicated function (or indeed data set; compare Chapter 5) by a simple polynomial which can be easily handled. The choice here is between a very good approximation of f(x) close to some given value x0 of x, which gets steadily worse as x moves away (Taylor polynomials), and a reasonably good approximation over a larger range (‘polyfit’ approximations). Each has its uses.
Polynomials
A polynomial such as p(x) = x4 + 2x3 − 3x2 + 4x + 5 is entered by means of its coefficients:
» p=[1 2 -3 4 5]
Note the spaces between the numbers; commas are also allowed for separation. In other words, a polynomial is just entered as a vector containing the coefficients, starting with the ‘leading’ coefficient in front of the highest power of the variable x.
The roots of p (i.e., the solutions of p(x) = 0) are obtained by typing
roots(p)
Notice that this finds the complex roots as well as the real ones. We can increase the number of figures displayed by typing
format long
We can draw the graph of p by typing
» x=-4: .05:2;
» y=polyval(p,x);
» plot(x,y)
The first line creates a vector x whose entries are the numbers from –4 to 2 at 0.05 intervals.
To save this book to your Kindle, first ensure no-reply@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.