Plot a scalar as a function of a parameter

Good morning everybody,
I would like to plot a scalar as a function of a parameter. In particular, I'd like to plot inflation volatility as a function of the parameter (phipi) of monetary policy. Inflation volatility is a vector, so defined:
for n=1:N
for t=2:T
pivolaC(1,n)=(pipiC(t,n)^2)/T;
end
end
PipiC is a function of phipi. Using plot (phipi, pivolaC) just gives me an empty figure.
(By the way, I tried the same trick using a scalar instead of a vector, that is, taking pivolaC(1,1), but the problem persists.
Could somebody help me, please?

Answers (1)

It should be as simple as:
for n = 1:N
for t = 2:T
pipiVal(1,n) = pipiC(t,n); % or however you get the phipi-values correspondin to
pivolaC(1,n) = (pipiC(t,n)^2)/T; % the values for which you calculate pivolaC
end
end
Then the plot should be:
plot(pipiVal,pivolaC)
Further, you only save away the pivolaC-value from the last step in the inner loop. The only reason I can think of in a hurry
where you need to loop anyway is if your pipiC-function stores some state-variable that is updated every time the function
is called. That's a dangerously sensitiv programming pattern, in this case it would be better to have a function that accepts an entire vector of t and loops over them. If you don't do anything like that this should be identical:
for n = 1:N
t = T;
pipiVal(1,n) = pipiC(t,n); % or however you get the phipi-values correspondin to
pivolaC(1,n) = (pipiC(t,n)^2)/T; % the values for which you calculate pivolaC
end
HTH

3 Comments

Thank you very much Mr. Gustavsson,
I think you get the point but further insights on what I am doing might be useful.
I am simulating an economic model in which the endogenous (inflation and output, that is "pipi" and "zz" in my code) are recursively estimated. Furthermore, I run a "Monte Carlo" simulation of length N, so to have N historical series for inflation and N historical series for output (all of them generted by the same model, of course).
Then I build up such statistics (inflation volatility, that is "pivola") and I am asking myself: what happens to inflation volaitlity when the coefficient of response to deviation of inflation from its steady state changes in the policy rule?
The point is that such "phipi" AFFECTS my model as long as the elements of the matricial/reduced form are affected.
T=200;
N=400;
sigma=0.157;
k=0.3;
beta=0.99;
po=0.35;
phipi=1.5;
phiz=0; %uso la calibrazione suggerita da Bullard, Evans and McCough (2005) - scelte di sigma e k- e da Prof. Massaro
B2C=[sigma 1-beta*phipi; k*sigma k+beta*(sigma+phiz)]
B1C=1/(sigma+phiz+k*phipi)
BC=B1C*B2C
yC=NaN(2,T,N);
yC(1,1,:)=0.1;
yC(2,1,:)=0.2;
kappaC=[1/(sigma+phiz+phipi*k); k/(sigma+phiz+phipi*k)]
aC=NaN(2,T,N);
aC(1,1,:)=1; %valori iniziali IDENTICI per
aC(2,1,:)=2; %le varie serie storiche
%MC simulation: I want N time series for "z" and N time series for "pi"
for n=1:N
for t=2:T
rn=randn(1,T);
yC(:,t,n)=BC*aC(:,t-1,n)+kappaC*rn(:,t);
aC(:,t,n)=aC(:,t-1,n)+t^(-1)*(yC(:,t,n)-aC(:,t-1,n));
end
end
zC=yC(1,:,:) ;
piC=yC(2,:,:);
zzC=squeeze (zC); %starting from z(1,T,N) returns a matrix zz(T,N) where the N historical series are "squezzed" horizzontally like | | | ...I(N)
pipiC=squeeze (piC);
So that, at the endo of the day, inflation volatility will be affected by change in "phipi" only thorugh the matrix BC and the vector KAPPAC.
It's not exactly clear what is the problem, to me this:
subplot(2,2,1)
imagesc(zzC)
subplot(2,2,4)
imagesc(pipiC)
subplot(2,2,2)
plot(zzC(:,1),pipiC(:,1),'-',zzC(:,1),pipiC(:,1),'.','markersize',15)
subplot(2,2,3)
plot(zzC(12,:),pipiC(12,:),'-',zzC(12,:),pipiC(12,:),'.','markersize',15)
your zzC matrix as a pseudo-colour image in the top left panel, the pipiC matrix as a pseudo-colour image in the bottom right panel, the first column of zzC and pipiC in the top right panel and the 12th row in the bottom left.
HTH

Sign in to comment.

Categories

Asked:

on 22 Sep 2019

Commented:

on 23 Sep 2019

Community Treasure Hunt

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

Start Hunting!