-
Notifications
You must be signed in to change notification settings - Fork 10
/
fs_specline.m
79 lines (69 loc) · 2.21 KB
/
fs_specline.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
%% Matlab Graph Scatter and Line Spectrum with Three Variables
% *back to* <https://fanwangecon.github.io *Fan*>*'s* <https://fanwangecon.github.io/Math4Econ/
% *Intro Math for Econ*>*,* <https://fanwangecon.github.io/M4Econ/ *Matlab Examples*>*,
% or* <https://fanwangecon.github.io/MEconTools/ *MEconTools*> *Repositories*
%%
% Generate k + b = w, color for each w, vectors of k and b such that k + b =
% w for each w
%
% There are two N by M matrix, A anb B.
%
% Values in Matrix A correspond to the x-axis, values in Matrix B correspond
% to the y-axis.
%
% The rows and columns in matrix A and B have some other meanings. In this case,
% we will give color to the columns.
%
% The columns is represented by vector C, which is another variable.
%%
% # Each line a different color representing variable 3
% # Legend labeling a subset of colors
% # X and Y could be asset choices, color could be utility, consumption etc.
%% Setting Up Data
close all
clear all
% Bounds
fl_b_bd = -10;
% Max and Mins
fl_w_max = 50;
fl_w_min = fl_b_bd;
fl_kp_max = fl_w_max - fl_b_bd;
fl_kp_min = 0;
% Grid Point Counts
it_w_i = 30;
it_kb_j = 30;
% Grids
ar_w = linspace(fl_w_min, fl_w_max, it_w_i);
ar_kp = linspace(fl_kp_min, fl_kp_max, it_kb_j);
mt_bp = ar_w - ar_kp';
mt_kp = ar_w - mt_bp;
mt_bl_constrained = (mt_bp < fl_b_bd);
mt_bp_wth_na = mt_bp;
mt_kp_wth_na = mt_kp;
mt_bp_wth_na(mt_bl_constrained) = nan;
mt_kp_wth_na(mt_bl_constrained) = nan;
% Flatten
ar_bp_mw_wth_na = mt_bp_wth_na(:);
ar_kp_mw_wth_na = mt_kp_wth_na(:);
ar_bp_mw = ar_bp_mw_wth_na(~isnan(ar_bp_mw_wth_na));
ar_kp_mw = ar_kp_mw_wth_na(~isnan(ar_kp_mw_wth_na));
%% Graphing
figure('PaperPosition', [0 0 7 4]);
hold on;
chart = plot(mt_bp_wth_na, mt_kp_wth_na, 'blue');
clr = jet(numel(chart));
for m = 1:numel(chart)
set(chart(m),'Color',clr(m,:))
end
if (length(ar_w) <= 50)
scatter(ar_bp_mw, ar_kp_mw, 5, 'filled');
end
xline(0);
yline(0);
title('Choice Grids Conditional on kp+bp=w')
ylabel('Capital Choice')
xlabel({'Borrowing or Saving'})
legend2plot = fliplr([1 round(numel(chart)/3) round((2*numel(chart))/4) numel(chart)]);
legendCell = cellstr(num2str(ar_w', 'kp+bp=%3.2f'));
legend(chart(legend2plot), legendCell(legend2plot), 'Location','northeast');
grid on;