{
 "metadata": {
  "language": "Julia",
  "name": "",
  "signature": "sha256:4cd0646a953b73fda0710cf9b8c8a6a4fcfe58307a906ba54105346491078b19"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "covar=eye(5);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "for i = 1:5\n",
      "    for j=1:5\n",
      "        if i==j\n",
      "            covar[i,j]=1.0\n",
      "        else\n",
      "            covar[i,j]=0.5\n",
      "        end\n",
      "    end\n",
      "end"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "covar"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 3,
       "text": [
        "5x5 Array{Float64,2}:\n",
        " 1.0  0.5  0.5  0.5  0.5\n",
        " 0.5  1.0  0.5  0.5  0.5\n",
        " 0.5  0.5  1.0  0.5  0.5\n",
        " 0.5  0.5  0.5  1.0  0.5\n",
        " 0.5  0.5  0.5  0.5  1.0"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "meanVec=rand(5)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 4,
       "text": [
        "5-element Array{Float64,1}:\n",
        " 0.92027 \n",
        " 0.379231\n",
        " 0.474405\n",
        " 0.866161\n",
        " 0.305309"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "lw=chol(covar,:L)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 5,
       "text": [
        "5x5 Triangular{Float64,Array{Float64,2},:L,false}:\n",
        " 1.0  0.0       0.0       0.0       0.0     \n",
        " 0.5  0.866025  0.0       0.0       0.0     \n",
        " 0.5  0.288675  0.816497  0.0       0.0     \n",
        " 0.5  0.288675  0.204124  0.790569  0.0     \n",
        " 0.5  0.288675  0.204124  0.158114  0.774597"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "lw*transpose(lw)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 6,
       "text": [
        "5x5 Array{Float64,2}:\n",
        " 1.0  0.5  0.5  0.5  0.5\n",
        " 0.5  1.0  0.5  0.5  0.5\n",
        " 0.5  0.5  1.0  0.5  0.5\n",
        " 0.5  0.5  0.5  1.0  0.5\n",
        " 0.5  0.5  0.5  0.5  1.0"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "?Base.LinAlg.BLAS.trsm"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stderr",
       "text": [
        "INFO: Loading help data...\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Base.LinAlg.BLAS.trsm(side, ul, tA, dA, alpha, A, B)\n",
        "\n",
        "   Returns the solution to \"A*X = alpha*B\" or one of the other three\n",
        "   variants determined by \"side\" (A on left or right of \"X\") and\n",
        "   \"tA\" (transpose A). Only the \"ul\" triangle of \"A\" is used.\n",
        "   \"dA\" indicates if \"A\" is unit-triangular (the diagonal is\n",
        "   assumed to be all ones).\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "Base.LinAlg.BLAS.trsm('L', 'L', 'N', 'N', 1.0, full(lw), covar)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 8,
       "text": [
        "5x5 Array{Float64,2}:\n",
        " 1.0   0.5          0.5          0.5       0.5     \n",
        " 0.0   0.866025     0.288675     0.288675  0.288675\n",
        " 0.0  -6.7987e-17   0.816497     0.204124  0.204124\n",
        " 0.0  -5.26625e-17  3.51083e-17  0.790569  0.158114\n",
        " 0.0   0.0          0.0          0.0       0.774597"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\\(full(lw), covar)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 9,
       "text": [
        "5x5 Array{Float64,2}:\n",
        " 1.0   0.5          0.5          0.5       0.5     \n",
        " 0.0   0.866025     0.288675     0.288675  0.288675\n",
        " 0.0  -6.7987e-17   0.816497     0.204124  0.204124\n",
        " 0.0  -5.26625e-17  3.51083e-17  0.790569  0.158114\n",
        " 0.0   0.0          0.0          0.0       0.774597"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "?Base.LinAlg.BLAS.trsv"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Base.LinAlg.BLAS.trsv(side, ul, tA, dA, alpha, A, b)\n",
        "\n",
        "   Returns the solution to \"A*X = alpha*b\" or one of the other three\n",
        "   variants determined by \"side\" (A on left or right of \"X\") and\n",
        "   \"tA\" (transpose A). Only the \"ul\" triangle of \"A\" is used.\n",
        "   \"dA\" indicates if \"A\" is unit-triangular (the diagonal is\n",
        "   assumed to be all ones)."
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "Base.LinAlg.BLAS.trsv('L','L', 'N', 'N', 1.0, full(lw), meanVec)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "ename": "LoadError",
       "evalue": "`trsv` has no method matching trsv(::Char, ::Char, ::Char, ::Char, ::Float64, ::Array{Float64,2}, ::Array{Float64,1})\nwhile loading In[11], in expression starting on line 1",
       "output_type": "pyerr",
       "traceback": [
        "`trsv` has no method matching trsv(::Char, ::Char, ::Char, ::Char, ::Float64, ::Array{Float64,2}, ::Array{Float64,1})\nwhile loading In[11], in expression starting on line 1"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "Base.LinAlg.BLAS.trsv('L', 'N', 'N', full(lw), meanVec)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 12,
       "text": [
        "5-element Array{Float64,1}:\n",
        "  0.92027  \n",
        " -0.0934193\n",
        "  0.0505053\n",
        "  0.534658 \n",
        " -0.28751  "
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\\(full(lw), meanVec)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 13,
       "text": [
        "5-element Array{Float64,1}:\n",
        "  0.92027  \n",
        " -0.0934193\n",
        "  0.0505053\n",
        "  0.534658 \n",
        " -0.28751  "
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 14
    }
   ],
   "metadata": {}
  }
 ]
}