How to create a sequence of matrices that depend on parameters whose values change?
Afficher commentaires plus anciens
Hi,
I have the following problem I'm trying to solve on Matlab: some matrices that depend on a set of parameters; I attribute values to the parameters and use the matrices to calculate law of motions for some variables.
I would like to make one of the parameters to change in a given interval and see how the law of motions vary. The way I see it, that would require creating a sequence of matrices, one for each value of the given parameter, and then solving the problem for each combination of matrices.
Any help on how to do it?
To make matters more clear, here goes an example. What I would like is to get a set of values for C1, C2 and M (at the end of the code) as delta changes.
%parameter values:
alpha = 3; beta = 0.99; chi = 1.55; eta = 0; rho = 0.5; sigma = 1; omega = 0.5; theta = 2.064;
%There is also a parameter “delta”, which I'd like to be:
delta = 0:0.1:2;
%calculate kappa:
kappa = (1-omega)*(1-beta*omega)/(alpha*omega);
%define the following matrices:
A0 = zeros(3,3); A0(1,1) = 1; A0(2,2) = 1; A0(2,1) = sigma^(-1); A0(3,3) = beta;
B0 = zeros(3,1); B0(1,1) = 1;
A1 = zeros(3,3); A1(1,1) = rho; A1(2,1) = sigma^(-1); A1(2,2) = 1; A1(3,2) = -kappa; A1(3,3) = 1;
%Element A1(2,3) is the only one that depends on delta:
A1(2,3) = sigma^(-1)*delta;
%calculate alternative state-space matrices:
A = inv(A0)*A1;
B = inv(A0)*B0;
%Jordan decomposition of A:
[p,lambda] = eig(A);
%rearrangement of Jordan form:
pstar = inv(p);
%sort eigenvectors and eigenvalues in ascending order:
val = abs(diag(lambda));
t = sortrows([val p'],1);
lambda = diag(t(:,1)); p = t(:,2:4)'; pstar = inv(p);
%partition the lambda, pstar and R = pstar*B matrices:
LAMBDA1=lambda(1,1); LAMBDA2=lambda(2:3,2:3);
P11=pstar(1,1); P12=pstar(1,2:3); P21=pstar(2:3,1); P22=pstar(2:3,2:3);
R=pstar*B;
% Matrices of solution of model:
C1=real(inv(P11-P12*inv(P22)*P21)*LAMBDA1*(P11-P12*inv(P22)*P21));
C2=real(inv(P11-P12*inv(P22)*P21)*R(1));
M=real(-inv(P22)*P21);
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!