NST PART 1A MATHEMATICAL BIOLOGY Conic Sections 1. What is

NST PART 1A MATHEMATICAL BIOLOGY
Lent Term
Practical Class 1
Conic Sections
In this practical we will use Matlab to explore what a conic section is, how to identify a function as a conic
section and how to sketch these functions by hand.
1. What is a conic section?
Do not be put off by the terminology – the aim of this part of the practical is to provide a visual
demonstration of the following statement:
A conic section is the curve produced from the intersection of a hollow cone(s) with a plane.
Depending on the orientation of this plane (flat surface), the resulting curve may either be a circle, ellipse,
parabola or hyperbola.
Task 1
(i) Start Matlab and find the file ‘ConicDemo.m’ in the x:\IANST\MB\Lent folder using the “Current
Folder” window in Matlab. Right click on the file name and click ‘Run’. Select add to path in pop up
window to get the program to run. You may need to wait a short while for the program to run. You
should now have a figure window entitled ‘Conic Sections’.

The window contains two graphs and three ‘sliders’. The large graph shows an hourglass
shape intersected by a plane (the hourglass shape is just two cones joined by their respective
apex), the smaller graph shows the conic section.

By default, the plane should be intersecting the lower cone and a circle should be shown in the
smaller graph. Use the sliders to explore how the angle of the plane intercepting the conic
affects the 2-D intersect.
(ii) Can you make a circle, ellipse, parabola and hyperbola? (See your lecture notes if you need
definitions for any of these.)
When the plane intersects the cone to give a closed curve, an ellipse is formed. The circle is a special case
of the ellipse: it is obtained when the plane is parallel to the base of the cone. When the plane is parallel to
the side of the cone, a parabola is formed. Anything else is a hyperbola. We will now use Matlab to
investigate this.
NEED HELP? ASK A DEMONSTRATOR!
1
2. Mathematical Expression for a conic section
The general equation of a conic section is given by
where , , , ,
and
are scalar constants.
Suppose we want to plot the following equation (1) in Matlab.
(1)
Task 2
(i)
Rearrange equation (1) so you have an equation of the form y = f(x).
Hint: Try substituting
and treating m as a constant solve for using the
quadratic formula – note you don’t need to attempt to solve the root and can plot both
and
(ii)
on the same plot.
Use the plot function to plot a graph of
against
over the range
.
Matlab should plot something but will also produce an error statement stating it cannot plot imaginary
numbers. There are a number of ways we can get round this in Matlab, but the most straightforward is to use
the built-in function ezplot which allows us to leave our equation as an implicit function i.e. we don’t
need to try to get the function in the form
.
ezplot('function')
where function is the equation you are trying to plot. Note the function needs to be in single quotation
marks and you do not need to specify a range of values for or .
Task 3
Try using ezplot for yourself by plotting equation (1)
>> ezplot('x.^2-4.*x+y.^2+6.*y=12')
You will notice that part of the curve is not shown. This is because, by default, Matlab plots the function for
the values of and between –
and
. If you want to change the range of x and y, modify the
command as follows:
ezplot('function' ,[xmin xmax ymin ymax])
where xmin, xmax, ymin and ymax are numerical values for the minimum and maximum values
on the x and y axis.
Task 4
Use ezplot to draw the following functions:
(i)
(ii)
(iii)
where
with a suitable domain,
and
where
and
, and
.
NEED HELP? ASK A DEMONSTRATOR!
2
3. Recognising the shape from the general form
We will focus on the special case
. This makes the analysis much simpler whilst retaining all the
features we are interested in. Thus, the general equation reduces to
(2)
Task 5
(i)
Create a function called conic which returns the value of the left hand side of equation (2)
for a given set of input parameters , , , , , and .
Hint: you can either create in a function file or as anonymous function (as show in Practical
7 last term) conic = @(x,y,a,c,d,e,f) a.*x.*x+c.*y.*y+d.*x+e.*y+f
(ii) To pass a function into ezplot, we need to use a slightly different syntax:
ezplot(@(x,y) conic(x, y, a, c, d, e, f))
where the parameters , , , and are numerical values within the function or defined prior to the
function. Test your function in ezplot, setting the parameter values to
;
;
;
and
.
This should produce a circle of radius 5 centred on the origin.
However, you may notice that your circle looks elliptical, even though you can clearly read that it has radius
. This happens because Matlab will try to fill the plot area as much as possible, thus stretching the circle in
the horizontal direction. This can be easily solved with the command
axis equal
Task 6
Try changing the parameters , , , and to see if you can produce a circle, ellipse, parabola or
hyperbola. Be careful to adjust the domain you use ezplot over. A too small domain may result in an
incomplete shape.
NOTE: If you are having trouble finding one or more of the shapes, the appendix to this practical
contains the shape classification. To get the most out of this exercise please use this ONLY after
having tried obtaining the various shapes on your own first.
NEED HELP? ASK A DEMONSTRATOR!
3
4. Sketching conic sections
Task 7
(a) Sketch by hand, without Matlab’s help, the equations below. You may use the appendix to this
practical for help.
i.
ii.
iii.
iv.
, and
v.
.
(b) Expand the equations given in part (a) above and use your conic function to check your
sketches using Matlab.
Optional Tasks: if you have time and would like to practice your programming further try the
following tasks:
Optional Task
Write a script file using the conditional statements if and elseif that
(i) plots the function
for any given values of , , ,
and , and
(ii) sets the graph title to tell the user the shape of the output (e.g. circle).
Use your script file to check your hand drawn sketches.
Extension of optional task
(i) Modify your script such that the title also gives you the centre in the case of the circle or ellipse.
(ii) Further modify your script such that it also outputs the radius for the circle and, the semi-major
and semi-minor axes for the ellipse.
NEED HELP? ASK A DEMONSTRATOR!
4
NEED HELP? ASK A DEMONSTRATOR!
5