Escolar Documentos
Profissional Documentos
Cultura Documentos
First Names:
Matlab commands in this worksheet follow a >>. Enter them exactly as they are shown.
Please printout this sheet and write your answers in the gaps provided. No cover sheet is
required. Hand in to the correct box on the Ground floor of Building 303. Late assignments or
assignments placed into incorrect boxes will not be marked.
1. Matlab can work symbolically with algebraic expressions; the variable names have to be declared
as symbolic:
>> syms x y z
We can now define y and z in terms of x.
>> y = x∧4 - 3*x∧2 - 2*x
This defines y as y = x4 − 3x2 − 2x. Note that we need to use * to tell Matlab to multiply by
the constants.
What does the Matlab operator ∧ do?
2. Matlab can solve an expression equal to zero. To solve x4 − 3x2 − 2x = 0, we use the command
>> solve(y)
Matlab gives the output as a temporary variable called ans. This will be overwritten by any
subsequent output. If we want to keep this output, we give it a name:
>> zero = solve(y)
3. If we were solving y = 0 by hand, we would factorise the expression. Matlab can do this for us:
>> factor(y)
Matlab can also expand an expression, which can also be useful:
>> z = (x-1)*(x-2)*(x-3)*(x-4)*(x-5)
>> expand(z)
Write the expanded polynomial:
z=
How many times does the graph of z cross the x-axis in the interval [0, 6]?
6. We know that z = 0 at several points. We might want to know the value of z another point.
>> p = subs(z,x,1.5)
This command substitutes the value of x = 1.5 into the expression for z, and calls this value p.
>> hold on; plot(1.5,p,’o’); hold off
The plot command can be used to draw other features on a graph; this command puts a circle
at the point (1.5, p). The hold on command keeps the graph from being redrawn, allowing
more graphs to be drawn over the top. The command to stop this is hold off.
The semicolons (;) in the above commands allow multiple commands on a single line.
We can “zoom in” on a function by changing the x- and y-axis bounds.
>> axis([1,2,0,4])
Is (1.5, p) at the peak of z? YES/NO
>> ezplot(2∧x)
2
>> hold on
>> ezplot(log2(x)) 1
>> ezplot(x) 0
>> grid on −3
Expect to see more Matlab commands and output in the assignments, test and exam.