File Exchange

image thumbnail

LqrSim

version 1.3.0.0 (173 KB) by

Algebraic Riccati Equation solution in Simulink via C+Fortran

12 Downloads

Updated

View License

This s-function solves Riccati equations in Simulink without calling the Matlab interpreter, it is FAST and usable with Real Time Workshop.

Specifically, the s-function is a level-2 gateway that calls several FORTRAN routines written by Arnold and Laub in the early eighties and publicly available under the cascade sublibrary of netlib. FORTRAN code is included in the Readme file, along with further instructions on how to compile and link the s-function.

Giampiero Campa, October 2002 and January 2009
Riccardo Bevilacqua & Jason Hall, NPS Spacecraft Robotics Lab, October 2008

Comments and Ratings (21)

@burak ergocmen, have you solved the problem. I'm also having the same problem here. Did u solve it?

>> mex sfun_lqrysim.c *.o
after that error occurs :
Error using mex
No supported compiler or SDK was found. For options, visit http://www.mathworks.com/support/compilers/R2014a/win64.

ı am new about that . When i download MinGW from sourceforge , there is no file like g77.exe. anybody help pls

Hoang Nguyen

Hi all,
Can it solve ARE to find Kalman filter gain?

Reurison

Samir,

Instead of use the command eval('! g77 -c *.f') in matlab, try to compile the *.f files directly in windows cmd command line. In my case the eval command was not generating the *.o files.
Go to the cmd and find the path where your *.f files are. Then compile using the command : g77 -c *.f
Like this you will generate the *.o files and then you could use :
mex sfun_lqrysim.c *.o

Samir

Samir (view profile)

I´m wondering why the matlab compiler cannot find the functions writen in fortran, that are used in the sfunction. I´m using mex sfun_lqrysim.c but it doesn´t work. Those functions are not found, even though I have compiled them with g77 compiler. I´m getting this errors:

Creating library C:\Users\SAMIRA~1\AppData\Local\Temp\mex_ug7vuD\templib.x and object C:\Users\SAMIRA~1\AppData\Local\Temp\mex_ug7vuD\templib.exp
sfun_lqrysim.obj : error LNK2019: unresolved external symbol creg_ referenced in function mdlOutputs
sfun_lqrysim.obj : error LNK2019: unresolved external symbol msub_ referenced in function mdlOutputs
sfun_lqrysim.obj : error LNK2019: unresolved external symbol mlineq_ referenced in function mdlOutputs
sfun_lqrysim.obj : error LNK2019: unresolved external symbol save_ referenced in function mdlOutputs
sfun_lqrysim.obj : error LNK2019: unresolved external symbol madd_ referenced in function mdlOutputs
sfun_lqrysim.obj : error LNK2019: unresolved external symbol xty_ referenced in function mdlOutputs
sfun_lqrysim.obj : error LNK2019: unresolved external symbol mmul_ referenced in function mdlOutputs
sfun_lqrysim.obj : error LNK2019: unresolved external symbol symprd_ referenced in function mdlOutputs
sfun_lqrysim.mexw64 : fatal error LNK1120: 8 unresolved externals

Do you have any idea where is the problem?

I need the code for investigation purpuses at my university so i would be very pleased if someone can help me.

Thanks

I can't seem to mex it in Matlab 2010. It fails when linking ... some unresolved symbols in scaleg.o

Unfortunately some other code that I have only works on 2010 ..

Hello again,
contact author is not working, yet. They know about it.

Concerning my problem: I have to compile it first, yes? G77 isn't part of minGW, but GFortran is. It compiles your *.f-files without comment or error, but the mex command cannot use the *.o-files. Matlab is r2007b. Error message is

File ... unknown section /4.

Please help.

Matlab is r2007b

Hello Mr. Campa,

sorry about any inconvenience: "Contact Author" is not working, somehow.

I tried using your lqrsim with realtimeworkshop, added the source-directory like explained in the readme-file but still got the following error when compiling:

COMPILING "d:\PROGRA~1\MATLAB\R2007b\rtw\c\src\rt_sim.c"
OPUS MAKE: Don't know how to make 'sfun_lqrysim.o03'. Stop.

Do I have to download the g77 compiler, as you explained for mex-files?

Please help me!

Best regards,
Jochen Schüttler

Jiang Wang

Hello Dr. Campa,

Thanks for your excellent work. I have one question: does this subroutine support solving discrete algebraic riccati equations? The Matlab command LQRY can do this for discrete system, but after I check your code, it seems that it doesn't have this option for discrete time system. Thanks.

Jiang Wang

Jason Hall

Very good in Matlab 2007b. As you code, obviously keep in mind that Q needs to be a real symmetric positive semi-definite matrix and R needs to be a real symmetric positive definite matrix. Furthermore, if R is ill-conditioned, this block will not compute the gain properly. Conversely, Matlab's LQRY function can still compute the gain matrix even with an ill-conditioned R matrix. Very good block though.

Martins _

Works very well on Matlab 2007b or older, but does not work on 2008.

Majdi Belguith

How could I add this application to Matlab
thanks

Cristian Gutiérrez

sorry, but it needs improvement.

javad heydari

xiaoming wang

ich grade brauche ihn, danke!!!

Wojtek S

Thank You Mr. Giampiero Campa . It works perfectly and saves time.

samu abdu

it is very useful for non mathematicians doing research in control theory.........

Paul Nune

Hi. I´m Paul from Portugal.
I´ve no words to describe your excelent work.

Thank you Mr. Giampiero Campa

Updates

1.3.0.0

Fully converted to BSD License

1.2.0.0

Many thanks to Jason Hall and Riccardo Bevilacqua for your excellent job in enabling native matrices inputs to the block and
using the open source g77 FORTRAN compiler to create mex files and RTW binaries under both Windows and Linux.

1.1.0.0

This version works with MATLAB 7.6 (R2008a), uses native matrix signals, is re-mexable on every platform, and is better integrated with real time workshop (Thanks Jason & Riccardo).

1.0.0.0

Recompiled mex files with matlab 7.1 so that everything works fine with newer versions requiring the .mexw32 extension. The .dll files are retained to the benefit users working with versions prior to 7.1, other users may delete them.

Changed info.xml file to avoid annoying messages within the last matlab versions.

Move it to simulink utilities.

Renamed everything lowercase

The file info.xml has been updated.

Instructions on how to compile with The Real Time Workshop have been added.

The fortran subfunctions have been
compiled using the multithreaded library
(DFORMT.LIB) and some optimization options.
As a result the DLL is smaller and runs faster.

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux

MATLAB Online Live Editor Challenge

Win cash prizes and have your live script featured on our website

Learn more

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video