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