UP | HOME

Exercise 22 solutions

Table of Contents


Python

e22.py

# ipython --pylab

# part 1
x = linspace(1,100,100)
y = (0.15 * x) + randn(100)
plot(x,y,'bo')
title("Noisy Data")
xlabel('X')
ylabel('Y')

# part 2
z = ((x * 0.05) + 2) + randn(100)
plot(x,z,'ro')
legend(("Y","Z"),loc="upper left")
ylabel("Y, Z")

MATLAB / Octave

e22.m

# part 1
x = linspace(1,100,100);
y = (0.15 * x) + randn(1,100);
plot(x,y,'b.','markersize',15)
title('Noisy Data')
xlabel('X')
ylabel('Y')

# part 2
hold on
z = ((x * 0.05) + 2) + randn(1,100)
plot(x,z,'r.','markersize',15)
ylabel('Y,Z')
legend('Y','Z','location','northwest')

R

e22.R

# part 1
x <- seq(1,100,1)
y <- (0.15 * x) + rnorm(100, 0.0, 1.0)
plot(x,y,type="p",col="blue",main="Noisy Data",pch=19, ylab="Y")

# part 2
plot(x,y,type="p",col="blue",main="Noisy Data",pch=19, ylab="Y,Z")
z = ((x * 0.05) + 2) + rnorm(100, 0.0, 1.0)
points(x,z,col="red",pch=19)
legend("topleft", legend=c("Y","Z"), col=c("blue","red"), pch=19)

Paul Gribble | fall 2014
This work is licensed under a Creative Commons Attribution 4.0 International License
Creative Commons License