Tutorial 2b – Matlab/Octave likelihood function

In this tutorial we formulate the likelihood function of the problem introduced in Tutorial 2 in Matlab/Octave and use Fesslix to perform the Bayesian inference. BUS-SuS is employed as inference method.

This tutorial is based on Tutorial 2a. Please perform Tutorial 2a before you start with this tutorial. The code given in this tutorial (Tutorial 2b) replaces the code given in Section 1.3 of Tutorial 2a. The code given in Sections 1.1 and 1.2 of Tutorial 2a precedes all code given in this tutorial (Tutorial 2b); and the code given in Sections 1.4 and 1.5 of Tutorial 2a succeedes all code given in this tutorial (Tutorial 2b).


For this tutorial you must have a 64-bit version of Matlab/Octave installed on your system. Under Windows, the Octave interface is currently not supported.

1   Step by Step Instruction

1.1   Matlab/Octave function file

We begin with the Matlab/Octave likelihood function. We create a file tutorial_2b_likeli.m with content:

Matlab/Octave Code "tutorial_2b_likeli.m"
function [resultScalar] = tutorial_2b_likeli(rvv)

  % define the dynamic system parameters:
  m1 = 16.5e3;
  m2 = 16.1e3;
  k1f = 29.7e6;
  k2f = 29.7e6;
  k1 = rvv(1)*k1f;
  k2 = rvv(2)*k2f;

  M = [m1 0 ; 0 m2];
  K = [k1 + k2, -k2; -k2, k2];

  [V,D] = eig(M^(-1)*K);

  freq = sqrt(diag(D))/(2*pi);
  % measured eigenfrequencies:
  freq_m1 = 3.13;
  freq_m2 = 9.83;

  % define likelihood
  i = 9;
  var_eps = 0.5^(i-1);
  resultScalar = exp(-sum((freq.^2 ./[freq_m2;freq_m1].^2-1).^2)/(2*var_eps));

end

1.2   Fesslix parameter file (Matlab interface)

First, we need to load the Matlab interface in Fesslix:

Fesslix parameter file
loadlib "matlab";
matlab_addpath($pwd()) { subfolders=true; }; # add current path to the search-path of Matlab


Now, we can link the Matlab likelihood function to Fesslix. In the Fesslix parameter file, we define the function likeli as follows:

Fesslix parameter file
fun likeli(2) = matlab_fun(tutorial_2b_likeli, {$1;$2} );


where matlab_fun evaluates the Matlab-function tutorial_2b_likeli that takes the vector {$1;$2} as input; with $1 and $2 being the two parameters of the function.

1.3   Fesslix parameter file (Octave interface)

First, we need to load the Octave interface in Fesslix:

Fesslix parameter file
loadlib "octave";


Now, we can link the Octave likelihood function to Fesslix. In the Fesslix parameter file, we define the function likeli as follows:

Fesslix parameter file
fun likeli(2) = octave_fun(tutorial_2b_likeli, {$1;$2} );


where octave_fun evaluates the Octave-function tutorial_2b_likeli that takes the vector {$1;$2} as input; with $1 and $2 being the two parameters of the function.

2   The complete input files of this tutorial

fesslix.org – Home  |  Contact  |  Impressum  |  © 2015-2017 Wolfgang Betz