# Octave script as limit-state function

The latest release of STRUREL offers an external interface to Octave – besides the already existing external interfaces to Matlab, Python, Maple, Mathematica and Ruby.

As most Matlab scripts can directly be run with Octave, we can directly use the Matlab example as demonstration example. The only difference is that `matlabs` needs to be replaced with `ocataves`. The full application example is presented in the following:

We use the example limit-state function RS that we already used for the Matlab example: Our stochastic model consists of the two random variables R and S, where R represents the resistance of a system of interest and S is the system load. The symbolic expression for the corresponding limit-state function in the native syntax of STRUREL would be:`FLIM(1) = R-S`

However, if you have Octave installed on your system and if the Octave interface of STRUREL is configured correctly, you could also use the following expression:

`FLIM(1) = octaves("my_model")`

where `my_model.m` is an Octave script file located in the same directory as the iti-file of STRUREL.

For the example at hand, the Octave script file should look as follows:

`function [lsfval] = my_model(INPUT)R = INPUT(1);S = INPUT(2);lsfval = R - Send`

The ordering of the random variables in the vector `INPUT` corresponds to the order in which they appear in the stochastic model of STRUREL.

Alternatively, the Octave script file could look as follows:

`function [lsfval] = my_model(INPUT)global R;global S;lsfval = R - Send`

where the variable names R and S must match the names of the random variables of the stochastic model of STRUREL.

By means of the STRUREL command `octaves`, you can integrate any limit-state function written in Matlab/Octave-Syntax directly in your reliability analysis performed with STRUREL.

# External interfaces » advanced in-line coding in Strurel

STRUREL supports the following five external engines: Matlab, Python, Maple, Mathematica and Ruby. In previous posts, we discussed exemplarily for Matlab and Python how in-line code and external scripts can be evaluated with STRUREL. In case computational performance matters, external scripts should be preferred over in-line code, as in-line code needs to be re-processed each time a limit-state function is evaluated.

Nevertheless, for testing purposes you might prefer to simply work with in-line code in STRUREL. For multi-line code, you can split-up your code as is shown in the following Python-based example:

`FLIM(1) = pythonf("%import math") + pythonf("%A=math.sqrt(R)") + pythonf("R-S+A")`

Note that the individual `pythonf`-calls are connected by a ‘+’. However, except for the actual limit-state function call `R-S+A`, all code-lines start with a ‘%’. This character is interpreted by STRUREL and not forwarded to the external engine (Python in the example above). The ‘%’ at the beginning of a code line tells STRUREL that the associated line of code does NOT return a value. In the example above, both R and S are random variables defined through STRUREL.

# How to re-start the Matlab-interface

STRUREL offers an interface to Matlab: You can evaluate Matlab functions or Matlab scripts within a limit-state function call.

The initial start of the Matlab engine takes a bit. Therefore, to be able to evaluate your Matlab-based limit-state function calls efficiently, we keep the Matlab engine running in the background. You need to be aware of this behavior, if you work with external Matlab scripts: When you change the content of your script, you need to manually restart the Matlab engine. Otherwise, the Matlab engine will not take the changes you made into account.

The simplest way to force a re-load of the engine is to close the Matlab engine actively. Add the following code in the ‘Symbolic Expressions‘ tab of STRUREL:

`FLIM(2)=matlabf("%quit")`

Now, you simply have to evaluate this limit-state function each time you want to enforce a re-start of the Matlab engine.

# Use a Python script as limit-state function

In one of the previous posts, we showed you how to work with in-line Python functions directly in STRUREL. Did you know? You can also use a Python script as limit-state function in STRUREL.

Again, we use the example limit-state function RS that we already used in the past: Our stochastic model consists of the two random variables R and S, where R represents the resistance of a system of interest and S is the system load. The symbolic expression for the corresponding limit-state function in the native syntax of STRUREL would be:

`FLIM(1) = R-S`

However, if you have Python installed on your system and if the Python interface of STRUREL is configured correctly, you could also use the following expression:

`FLIM(1) = pythons("my_model")`

where `my_model.py` is a Pyhton script file located in the same directory as the iti-file of STRUREL.

For the example at hand, the Python script file should look as follows:

`res = R - S`

where the variable names `R` and `S` must match the names of the random variables of the stochastic model of STRUREL. The variable `res` must contain the value of the limit-state function, where the value of `res` is later retrieved by STRUREL.

By means of the STRUREL command `pythons`, you can integrate any limit-state function written in Python directly in your reliability analysis performed with STRUREL.

# Use a Matlab script as limit-state function

In one of the previous posts, we showed you how to work with in-line Matlab functions directly in STRUREL. Did you know? You can also use a Matlab script as limit-state function in STRUREL.

Again, we use the example limit-state function RS that we already used in the past: Our stochastic model consists of the two random variables R and S, where R represents the resistance of a system of interest and S is the system load. The symbolic expression for the corresponding limit-state function in the native syntax of STRUREL would be:

`FLIM(1) = R-S`

However, if you have Matlab installed on your system and if the Matlab interface of STRUREL is configured correctly, you could also use the following expression:

`FLIM(1) = matlabs("my_model")`

where `my_model.m` is a Matlab script file located in the same directory as the iti-file of STRUREL.

For the example at hand, the Matlab script file should look as follows:

`function [lsfval] = my_model(INPUT)R = INPUT(1);S = INPUT(2);lsfval = R - Send`

The ordering of the random variables in the vector `INPUT` corresponds to the order in which they appear in the stochastic model of STRUREL.

Alternatively, the Matlab script file could look as follows:

`function [lsfval] = my_model(INPUT)global R;global S;lsfval = R - Send`

where the variable names R and S must match the names of the random variables of the stochastic model of STRUREL.

By means of the STRUREL command `matlabs`, you can integrate any limit-state function written in Matlab-Syntax directly in your reliability analysis performed with STRUREL.

# How to use in-line Matlab in Strurel

In the last post, we showed you how to work with in-line Python functions directly in STRUREL. Did you know? You can also use in-line Matlab functions directly in a symbolic expression in STRUREL.

For example, assume a problem for which you have the two random variables R and S in your stochastic model, where R represents the resistance of a system of interest and S is the system load. The symbolic expression for the corresponding limit-state function in the native syntax of STRUREL would be:

`FLIM(1) = R-S`

However, if you have Matlab installed on your system and if the Matlab interface of STRUREL is configured correctly, you could also use the following expression:

`FLIM(1) = matlabf("R-S")`

Sure, calling the Matlab interpreter for this simple demonstration example is like taking a sledgehammer to crack a nut. However, the interface-function `matlabf` is a tool that gives you access to the full power of Matlab directly in the symbolic expression of STRUREL.

# How to use in-line Python in Strurel

Did you know? You can use in-line Python functions directly in a symbolic expression in STRUREL.

For example, assume a problem for which you have the two random variables R and S in your stochastic model, where R represents the resistance of a system of interest and S is the system load. The symbolic expression for the corresponding limit-state function in the native syntax of STRUREL would be:

`FLIM(1) = R-S`

However, if you have Python installed on your system and if the Python interface of Strurel is configured correctly, you could also use the following expression:

`FLIM(1) = pythonf("R-S")`

Sure, calling the Python interpreter for this simple demonstration example is like taking a sledgehammer to crack a nut. However, the interface-function `pythonf` is a tool that gives you access to the full power of Python directly in the symbolic expression of Strurel.

# STRUREL 2020 is available

The new release of STRUREL is available. We have added many helpful features to our software packages COMREL, SYSREL and COSTREL. Most notably, we extended the external interface of STRUREL: All our packages can now be coupled to C/C++, FORTRAN, Maplesoft Maple, Wolfram Mathematica, MathWorks Matlab, Python and Ruby. It is now straight-forward to use an external interface of STRUREL in your analysis. We also pushed our Add-On Feature to a new level, so that you can work with complex and challenging limit-state functions and share your projects with others.

# Final Reminder: Short Course in December

There is still a small number of seats available for our short course on ‘Uncertainty and Reliability in Engineering’, which takes place in Munich on December 2 to 3.

The course fee includes a 1-hour consulting session!

Registration and program: https://eracons.com/short-course

# Reminder: Short Course in December

This is a reminder that we organize a short course on ‘Uncertainty and Reliability in Engineering’. It takes place in Munich on December 2 to 3.

The course fee includes free consulting on a problem of your choice.

Registration and program: https://www.eracons.com/short-course