source: projects/ckbs/trunk/test/affine_ok_box.r @ 95

Last change on this file since 95 was 27, checked in by bradbell, 11 years ago

Coppied from Brad's cvs repository on 2010-01-15

File size: 1.8 KB
Line 
1# read data file as character vector
2data   <- scan(file="affine_ok_box.out", what="character")
3#
4# set some line types
5no_line  <- 0
6solid    <- 1
7dashed   <- 2
8dotted   <- 3
9dotdash  <- 4
10longdash <- 5
11twodast  <- 6
12#
13# minimum allowable value for x2(t)
14x2_min <- -1
15#
16# convert to a character matrix
17len    <- length(data)
18nc     <- 5
19#
20# separate from the header line
21header <- data[1 : nc]
22data   <- data[(nc+1) : len]
23#
24# convert data to double precision
25data   <- as.double(data)
26#
27# convert to a matrix
28nr     <- (len - 1)  / nc
29data   <- matrix(data, nrow=nr, ncol=nc, byrow=TRUE)
30#
31# plot the data
32circle <- 21
33t      <- data[, "t" == header]
34x2_z   <- data[, "z1" == header]
35plot(
36        x = t, 
37        y = x2_z, 
38        type = "p", 
39        main = "Affine Kalman-Bucy Smoother",
40        xlab = "t", 
41        ylab = "x2", 
42        lty=no_line
43)
44#
45# plot true values with dotted line
46x2_true <- data[, "x2_true" == header]
47lines(x = t, y = x2_true, type = "l", lty=dotted)
48#
49# plot lower and upper bounds with a straight line
50x1_bnd   <- c(0, 2*pi)
51x2_low   <- c(x2_min, x2_min)
52x2_up    <- c(2 + x2_min, 2 + x2_min)
53lines(x = x1_bnd, y = x2_low, type = "l", lty=solid)
54lines(x = x1_bnd, y = x2_up,  type = "l", lty=solid)
55#
56# plot constrained estimate with longdash line
57x2_con   <- data[, "x2_con" == header]
58lines(x = t, y = x2_con, type = "l", lty=longdash)
59#
60# plot unconstrained estimate with dashed line
61x2_free <- data[, "x2_free" == header]
62lines(x = t, y = x2_free, type = "l", lty=dashed)
63#
64# add legend to plot
65yleg    <- 2.4
66xleg    <- .1
67no_sym  <- -1
68legend (
69        x = xleg , 
70        y = yleg, 
71        legend = c( "meas",  "true",     "con",    "free",   "bound"), 
72        lty    = c(no_line,   dotted,  longdash,  dashed,     solid),
73        pch    = c( circle,  no_sym,    no_sym,    no_sym,    no_sym)
74)
75#
76# save the plot in encapsulated postscript
77savePlot(filename = "affine_ok_box", type = "eps");
Note: See TracBrowser for help on using the repository browser.