source: projects/ckbs/trunk/test/nonlinear_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.6 KB
Line 
1# read data file as character vector
2data   <- scan(file="nonlinear_ok_box.out", what="character")
3#
4# minimum allowable value for x4(t)
5x4_min <- .25
6#
7# convert to a character matrix
8len    <- length(data)
9nc     <- 8
10#
11# separate from the header line
12header <- data[1 : nc]
13data   <- data[(nc+1) : len]
14#
15# convert data to double precision
16data   <- as.double(data)
17#
18# convert to a matrix
19nr     <- (len - 1)  / nc
20data   <- matrix(data, nrow=nr, ncol=nc, byrow=TRUE)
21#
22# plot true values with solid line
23solid   <- 1
24x2_true <- data[, "x2_true" == header]
25x4_true <- data[, "x4_true" == header]
26plot(
27        x = x2_true, 
28        y = x4_true, 
29        type = "l", 
30        ylim = c(0, 2.5),
31        main = "Nonlinear Kalman-Bucy Smoother",
32        xlab = "x2", 
33        ylab = "x4", 
34        lty=solid
35)
36#
37# plot lower and upper bounds with a straight line
38x2_bnd   <- c(0, 2*pi)
39x4_low   <- c(x4_min, x4_min)
40x4_up    <- c(2 + x4_min, 2 + x4_min)
41lines(x = x2_bnd, y = x4_low, type = "l", lty=solid)
42lines(x = x2_bnd, y = x4_up,  type = "l", lty=solid)
43#
44# plot constrained estimate with longdash line
45longdash <- 5
46x2_con   <- data[, "x2_con" == header]
47x4_con   <- data[, "x4_con" == header]
48lines(x = x2_con, y = x4_con, type = "l", lty=longdash)
49#
50# plot unconstrained estimate with dotted line
51dotted <- 3
52x2_free <- data[, "x2_free" == header]
53x4_free <- data[, "x4_free" == header]
54lines(x = x2_free, y = x4_free, type = "l", lty=dotted)
55#
56# add legend to plot
57xleg    <- .3 
58yleg    <- 2.
59legend (
60        x = xleg , 
61        y = yleg, 
62        legend = c("true",     "con",   "free"), 
63        lty    = c( solid,  longdash,   dotted) 
64)
65#
66# save the plot in encapsulated postscript
67savePlot(filename = "nonlinear_ok_box", type = "eps");
Note: See TracBrowser for help on using the repository browser.