How to use Matlab to estimate parameters of the autoregressive(AR) model with input-output delay? - matlab

I know there are several functions, such as aryule and arborg, which can estimate coefficients of AR models. But these functions cannot deal with AR models with input-output delay.
I also learned that the newest Matlab includes a function named 'arx' that can estimate AR parameters including the input-output delay. Unfortunately, the current version of Matlab I used is 2013a and I didn't find this 'arx' function inside.
I am wondering if anybody would kindly help me to tackle this issue.

Related

Are there any softwares that implemented the multiple output gauss process?

I am trying to implement bayesian optimization using gauss process regression, and I want to try the multiple output GP firstly.
There are many softwares that implemented GP, like the fitrgp function in MATLAB and the ooDACE toolbox.
But I didn't find any available softwares that implementd the so called multiple output GP, that is, the Gauss Process Model that predict vector valued functions.
So, Are there any softwares that implemented the multiple output gauss process that I can use directly?
I am not sure my answer will help you as you seem to search matlab libraries.
However, you can do co-kriging in R with gstat. See http://www.css.cornell.edu/faculty/dgr2/teach/R/R_ck.pdf or https://github.com/cran/gstat/blob/master/demo/cokriging.R for more details about usage.
The lack of tools to do cokriging is partly due to the relative difficulty to use it. You need more assumptions than for simple kriging: in particular, modelling the dependence between in of the cokriged outputs via a cross-covariance function (https://stsda.kaust.edu.sa/Documents/2012.AGS.JASA.pdf). The covariance matrix is much bigger and you still need to make sure that it is positive definite, which can become quite hard depending on your covariance functions...

Optimization in NMPC of second order pendulum model

Hopefully, I will be able to explain my question well.
I am working on Nonlinear model predictive control implementation.
I have got 3 files:
1). a simulink slx file which is basically a nonlinear pendulum model.
2). A function file, to get the cost function from the simulink model.
3). MPC code.
code snippet of cost function
**simOut=sim('NonlinearPendulum','StopTime', num2str(Np*Ts));**
%Linearly interpolates X to obtain sampled output states at time instants.
T=simOut.get('Tsim');
X=simOut.get('xsim');
xt=interp1(T,X,linspace(0,Np*Ts,Np+1))';
U=U(1:Nu);
%Quadratic cost function
R=0.01;
J=sum(sum((xt-repmat(r,[1 Np+1])).*(xt-repmat(r,[1 Np+1]))))+R*(U-ur)*...
(U-ur)';
Now I take this cost function and optimize it using fmincon to generate a sequence of inputs to be applied to the model, using my MPC code.
A code snippet of my MPC code.
%Constraints -1<=u(t)<=1;
Acons=[eye(Nu,Nu);-eye(Nu,Nu)];
Bcons=[ones(Nu,1);ones(Nu,1)];
options = optimoptions(#fmincon,'Algorithm','active-set','MaxIter',100);
warning off
for a1=1:nf
X=[]; %Prediction output
T=[]; %Prediction time
Xsam=[];
Tsam=[];
%Nonlinear MPC controller
Ubreak=linspace(0,(Np-1)*Ts,Np); %Break points for 1D lookup, used to avoid
% several calls/compilations of simulink model in fmincon.
**J=#(v) pendulumCostFunction(v,x0,ur,r(:,a1),Np,Nu,Ts);**
U=fmincon(J,U0,Acons,Bcons,[],[],[],[],[],options);
%U=fmincon(J,U0,Acons,Bcons);
U0=U;
UUsam=[UUsam;U(1)];%Apply only the first selected input
%Apply the selected input to plant.
Ubreak=[0 Ts]; %Break points for 1D lookup
U=[UUsam(end) UUsam(end)];
**simOut=sim('NonlinearPendulum','StopTime', num2str(Ts));**
In both the codes, I have marked the times we call our simulink model. Now, issue is that to run this whole simulation for just 5 seconds it takes around 7-8 minutes on my windows machine, MATLAB R2014B.
Is there a way to optimize this? As, I am planning to extend this algorithm to 9th order system unlike 2nd order pendulum model.
If, anyone has suggestion on using simulink coder to generate C code:
I have tried that, and the problem I face is that I don't know what to do with the several files generated. Please be as detailed as possible.
From the code snippets, it appears that you are solving a linear time invariant model with a quadratic objective. Here is some MATLAB (and Python) code for an overhead crane pendulum and inverted pendulum, both with state space linear models and quadratic objectives.
One of the ways to make it run faster is to avoid a Simulink interface and a shooting method for solving the MPC. A simultaneous method with orthogonal collocation on finite elements is faster and also enables higher index DAE model forms if you'd like to use a nonlinear model.

How do I integrate an MPC, PID and System models together to simulate on Matlab

I have a system with a Model Predictive Controller and PID Controller.
Assuming I have models for each controller and can express them in discrete time, please how do I integrate them together to simulate properties of the system in matlab?
Thanks
... continuing from the comments.
This is what Simulink is made for. Of course there are ways to do it without Simulink, but often you still use Simulink tools and functions just without the graphical Interface.
I assume you have your transfer functions "on paper". So you need the tf function to define your system model.
G = tf(num,den)
num and den are the coefficient vectors of your transfer function of numerator and denumerator. In Simulink you use the Transfer Fcn block and you define it with
G.num{1} %Numerator coefficients
G.den{1} %Denumerator coefficients
Your PID-controller cannot be defined using this block, as Simulink requires a higher or equal order for the denumerator. Instead use the PID controller Block. You need to calculate the Proportional, Integral and Differential gain before.
Then read the documentation about the MPC toolbox - I'm not familiar with it and can't help you on that - it is explained how you can create an mpc object regarding all your constraints (see your other question).
Then you have various options to transform your mpc object into something Simulink can deal with. I'd recommend the ss - the state space model - which can be implemented using the state space block. There is also a MPC Controller block, I don't have the toolbox - but you'll be able to find out how it can be used.
Finally you find source blocks, like a step to generate a test signal. And there are Sinks, in the easiest case scope to display your results. You can also save them to workspace or whatever...

Automatically generate circuits on its own in PLECS (Piece-wise Linear Electrical Circuit Simulation )

Is there any way I could program the Matlab/Simulink to be able to automatically generate circuits on its own? I am using PLECS blockset (Piece-wise Linear Electrical Circuit Simulation ) embedded in Simulink.
For example, I need to have hundreds of identical block in a single .mdl file, instead of inserting one by one by myself by calling the block which I previously saved in Simulink library, is it possible that Simulink can be programmed to automatically generate hundreds of blocks by itself?
The only way I was told is by "using vectorization for most components. Most components are vectorized if they have a vectorized input signal or if one of their parameter is specified as a vector." However, I could not find any further information/details, appreciate if anyone of you could give opinion on this?
I just want to know if this is possible? Else, I would have to try another approach?
Thanks!
edited on 10 July 2013: Further to my question, I have confirmed with Plexim that there isn't such features ( add_block and add_line) in Plecs (Piece-wise Linear Electrical Circuit Simulation), does anyone know if there is any way I could automate the Plecs model? Appreciate any suggestion...Thanks
You can probably use functions like add_block and add_line to automate the creation of your Simulink model from a library.

svmtrain function in matlab never exits ... do alternatives exist?

I am trying to learn how to use support vector machines in matlab. I have the bioinformatics toolbox, which has SVM functions svmtrain and svmclassify.
I managed to successfully use it for some reference data sets, with some nice accuracy. When I try to use the svm on my actual data the training never stops. My data set is 400 instances in 25 dimensions, so it should not take very long?!
Can I use other solvers in matlab? I dont want to buy new toolbox please ...
There are several things that may cause problems for training, but it should not run infinitely. Do you get any errors when using the solver?
With regard to alternatives: LIBSVM has an interface to matlab. This is a state-of-the-art library with thousands of users. I highly recommend it, because it is easy to install/use and offers additional functionality for parameter tuning and more.