Professional Documents
Culture Documents
CHE317 Lecture 2
CHE317 Lecture 2
5.5
4.5
4
2 2.2 2.4 2.6 2.8 3 3.2 3.4
• Read about the secant code and use it to
find the root to tanh(x)=x/3
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
• Plot of y = x2
• We could make use of any colour for
the line.
• Let’s make the line green by adding a
third input
• >> x=-1:.1:1; y=x.^2;
• >> plot(x,y, 'g.') This gives the graph
below:
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
• Plot of y = x2
• The period after g indicates that the
plot should be shown with the
individual points.
• For a continuous curve remove the
point.
• >> x=-1:.1:1; y=x.^2;
• >> plot(x,y, 'g') This gives
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
• Simply type the 1st letter of any colour
you desire and it will plot with the
colour
• >> x=-1:.1:1; y=x.^2;
• >> plot(x,y, 'r.') This is red with dotted
curve.
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
• >> x=-1:.1:1; y=x.^2;
• >> plot(x,y, 'y') yellow
• >> plot(x,y, 'b') blue
• >> plot(x,y, 'p')purple
• Etc
Generally plots need not be a function in
the mathematical sense of the word:
For instance t=-1:.01:2*pi; x=sin(5*t);
y=cos(3*t); plot(x,y,'r')
1
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
• Practice this:
• Plot the function sinx vs. x , for
x∈[0,6π]………..
• Learn how to plot two functions with
the same plot command, and plot sinx
and cosx vs. x
• plot and figure out how to do the
following:
• Plot only the points and not the lines