MATLAB绘制函数图形和绘制六线型图形

临风暖阳 发表于 2022/11/25 21:44:46 2022/11/25
【摘要】 MATLAB绘制函数图形和绘制六线型图形

% close all

figure();
hold on;

% Define parameters

e1 = 1.5;
e2 = 1.9;
r = 0.05;
u_star = 1.5;
beta = 0.9;

% Define a function
% x = c1, f_x = c2

syms x

f_x_indiff = exp((u_star - log(x))/beta);

% Formula for optimal choice that minimize expenditure

4
c2_star_exp_min = exp((u_star + log(beta*(1+r)))/(1+beta));
c1_star_exp_min = (1/(beta*(1+r)))*c2_star_exp_min;
f_optimal_cost = c1_star_exp_min*(1+r)+c2_star_exp_min;

% budget equation
% x = c1, f_x = y

f_x_budget = (e1*(1+r) + e2) + (-1)*(1+r)*x;
f_x_budget_optimal_cost = f_optimal_cost + (-1)*(1+r)*x;

% Set bounds on the domain

fl_x_lower = 0;
fl_x_higher = 6;

% Graph

hold on;
fplot(f_x_indiff, [fl_x_lower, fl_x_higher])
fplot(f_x_budget, [fl_x_lower, fl_x_higher])
fplot(f_x_budget_optimal_cost, [fl_x_lower, fl_x_higher])

% plot a one point scatter plot

scatter(c1_star_exp_min, c2_star_exp_min, 300, 'filled');

% Add x-axis and y-axis

xline(0);
yline(0);

% Title and y and y-able

title(['Plot function: ' char(f_x_indiff)],'Interpreter',"none");
ylabel('c2');
xlabel('c1');

% this sets x and y visual boundaries

ylim([0,6]);
xlim([0,6]);

% Add grids

grid on;
grid minor;

close all

figure();
hold on;
blue = [57 106 177]./255;
red = [204 37 41]./255;
black = [83 81 84]./255;
green = [62 150 81]./255;
brown = [146 36 40]./255;
purple = [107 76 154]./255;
cl_colors = {blue, red, black, ...

 green, brown, purple};
cl_legend = {'For Borr', 'Inf Borr', 'For+Inf Br', 'For+Br+Save', 'Bridge Loan', 'For Save'};
cl_scatter_shapes = {'s','x','o','d','p','*'};
cl_linestyle = {'--','-',':','-.','--','-'};
it_sca_bs = 20;
cl_scatter_csizes = {10*it_sca_bs, 20*it_sca_bs, 10*it_sca_bs, 10*it_sca_bs, 5*it_sca_bs, 8*it_sca_bs};
it_line_bs = 2;
cl_line_csizes = {1*it_line_bs, 2*it_line_bs, 1*it_line_bs, 1*it_line_bs, 1*it_line_bs, 2*it_line_bs};
it_x_groups_n = length(cl_scatter_csizes);
it_x_n = 10;

% Generate Random Data

rng(123);
mat_y = rand([it_x_n, it_x_groups_n]);
mat_y = mat_y + sqrt(1:it_x_groups_n);
mat_y = mat_y + log(1:it_x_n)';
ar_x = 1:1:it_x_n;
ar_it_graphs_run = 1:6;
it_graph_counter = 0;
ls_chart = [];

for it_fig = ar_it_graphs_run
 % Counter

 it_graph_counter = it_graph_counter + 1;
 % Y Outcome

 ar_y = mat_y(:, it_fig)';
 % Color and Size etc

 it_csize = cl_scatter_csizes{it_fig};
 ar_color = cl_colors{it_fig};

1
 st_shape = cl_scatter_shapes{it_fig};
 st_lnsty = cl_linestyle{it_fig};
 st_lnwth = cl_line_csizes{it_fig};
 
 % plot scatter and include in legend

 ls_chart(it_graph_counter) = scatter(ar_x, ar_y, it_csize, ar_color, st_shape);
 % plot line do not include in legend

 line = plot(ar_x, ar_y);
 line.HandleVisibility = 'off';
 line.Color = ar_color;
 line.LineStyle = st_lnsty;
 line.HandleVisibility = 'off';
 line.LineWidth = st_lnwth;
 % Legend to include

 cl_legend{it_graph_counter} = cl_legend{it_fig};

end

% Legend

legend(ls_chart, cl_legend, 'Location', 'southeast');

% labeling

title('Optimal Savings');
ylabel('Savings Levels');
xlabel('Cash-on-Hand Today');
grid on;

开发工具:MATLAB2021b和 微信快捷截屏工具Alt+A

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区),文章链接,文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至:cloudbbs@huaweicloud.com进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。