Book contents
- Frontmatter
- Contents
- Preface
- Part one Foundations
- 1 Introduction
- 2 Matrices and Complex Numbers
- 3 Whole Numbers
- 4 Graphs and Curves
- 5 Representation of Data
- 6 Probability and Random Numbers
- 7 Differential and Difference Equations
- Part two Investigations
- Part three Modelling
- Appendix 1 MATLAB Command Summary
- Appendix 2 Symbolic Calculations within MATLAB
- Appendix 3 List of All M-files Supplied
- Appendix 4 How to Get Solution M-files
- Appendix 5 Selected MATLAB Resources on the Internet
- References
- Index
4 - Graphs and Curves
Published online by Cambridge University Press: 08 February 2010
- Frontmatter
- Contents
- Preface
- Part one Foundations
- 1 Introduction
- 2 Matrices and Complex Numbers
- 3 Whole Numbers
- 4 Graphs and Curves
- 5 Representation of Data
- 6 Probability and Random Numbers
- 7 Differential and Difference Equations
- Part two Investigations
- Part three Modelling
- Appendix 1 MATLAB Command Summary
- Appendix 2 Symbolic Calculations within MATLAB
- Appendix 3 List of All M-files Supplied
- Appendix 4 How to Get Solution M-files
- Appendix 5 Selected MATLAB Resources on the Internet
- References
- Index
Summary
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.
- Type
- Chapter
- Information
- Mathematical Explorations with MATLAB , pp. 44 - 59Publisher: Cambridge University PressPrint publication year: 1999