필터 지우기
필터 지우기

How to create a sequence of matrices that depend on parameters whose values change?

조회 수: 4 (최근 30일)
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);

채택된 답변

Nihar Deodhar
Nihar Deodhar 2016년 6월 23일
%Seems like you could use a simple for loop to run the code.
%The delta could be set as vector:
delta = 0:0.1:2;
%use a variable say 'd' to substitute delta in the matrix at location A1(2,3)
for i = 1:length(delta)
d = delta(i);
%% than execute the rest of the code above and put d at A1(2,3). % If C1, C2 and M are scalars and you wish to have all of them at once, % index them as C1(i) and C2(i) and M(i).
end
  댓글 수: 4

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by