Please help to correct my code

조회 수: 15 (최근 30일)
Jiiim Wu
Jiiim Wu 2023년 7월 14일
댓글: Jiiim Wu 2023년 7월 14일
% Parameters
alpha = 0.3;
epsilon = 0.4;
K_bar = 1;
R = 1.05;
z_bar = 2;
z_min = 0;
z_max = 2;
% Number of points for simulation
num_points = 100; % Adjust as needed
% Array to store results
z_underline = linspace(0.1, 1, num_points);
z_ast = zeros(1, num_points);
% Simulation
for i = 1:num_points
% Calculate P_i
z_vals = linspace(z_min, z_max, num_points);
P_i = (R / (epsilon * alpha * z_underline(i) * z_vals.^alpha)) .* ...
((R / (epsilon * alpha * z_underline(i))).^((1 - alpha) / alpha));
% Calculate Hat(P)
hat_P = (trapz(z_vals(z_vals > z_ast(i)), P_i(z_vals > z_ast(i)).^(epsilon / (epsilon - 1))))^((epsilon - 1) / epsilon);
% Calculate z_ast
z_ast(i) = (R^(1 + alpha * epsilon - epsilon) * hat_P^((1 - epsilon * alpha) / (alpha * epsilon)) * ...
(1 / (epsilon * alpha))^((1 / (alpha * epsilon))) * K_bar^((epsilon - 1) / (alpha * epsilon)) * ...
(1 / z_underline(i))^(1 / alpha) * (alpha / (1 - alpha))^((epsilon - alpha * epsilon) / (alpha * epsilon)) * ...
(1 / (epsilon * alpha) - 1 / alpha)^((epsilon - 1) / (alpha * epsilon)) * (1 / K_bar)^((epsilon - 1) / (alpha * epsilon)));
end
% Plotting
plot(z_underline, z_ast);
xlabel('\underline{z}');
ylabel('z^*');
title('Relation between \underline{z} and z^*');
My price function is determined by z_i, which is the only variable. And \hat_P is the aggregator function. It aggregates the firms' prices with z_i greater than z*. I want to simulate z* and its relation with underline_z
  댓글 수: 4
Dyuman Joshi
Dyuman Joshi 2023년 7월 14일
"I want to express the value between z* and underline z."
Do you want to calculate the integratal shown in the first image you have attached?
Jiiim Wu
Jiiim Wu 2023년 7월 14일
Yes. I want to calculate P_i and then \Hat{P}. And then compute z*. Since Z* is a function of \underline{z}. I want to express the relationship between them. the only random variable is z_i

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

답변 (2개)

Dyuman Joshi
Dyuman Joshi 2023년 7월 14일
You need to use element-wise operators for the variable P_i
% Parameters
alpha = 0.3;
epsilon = 0.4;
K_bar = 1;
R = 1.05;
z_bar = 2;
z_min = 0;
z_max = 2;
% Number of points for simulation
num_points = 100; % Adjust as needed
% Array to store results
z_underline = linspace(0.1, 1, num_points);
z_ast = zeros(1, num_points);
% Simulation
for i = 1:num_points
% Calculate P_i
z_vals = linspace(z_min, z_max, num_points);
%%% v element-wise division
P_i = (R ./ (epsilon * alpha * z_underline(i) * z_vals.^alpha)) .* ...
((R ./ (epsilon * alpha * z_underline(i))).^((1 - alpha) / alpha));
% Calculate Hat(P)
hat_P = (trapz(z_vals(z_vals > z_ast(i)), P_i(z_vals > z_ast(i)).^(epsilon / (epsilon - 1))))^((epsilon - 1) / epsilon);
% Calculate z_ast
z_ast(i) = (R^(1 + alpha * epsilon - epsilon) * hat_P^((1 - epsilon * alpha) / (alpha * epsilon)) * ...
(1 / (epsilon * alpha))^((1 / (alpha * epsilon))) * K_bar^((epsilon - 1) / (alpha * epsilon)) * ...
(1 / z_underline(i))^(1 / alpha) * (alpha / (1 - alpha))^((epsilon - alpha * epsilon) / (alpha * epsilon)) * ...
(1 / (epsilon * alpha) - 1 / alpha)^((epsilon - 1) / (alpha * epsilon)) * (1 / K_bar)^((epsilon - 1) / (alpha * epsilon)));
end
% Plotting
plot(z_underline, z_ast);
Some symbols (underscore ( _ ) for subscript and caret ( ^ ) for superscript, etc) in have a predefined meaning (TeX characters) while dealing the text in MATLAB. Use the backslash character with these symbols to bypass the interpeter.
xlabel('z\_underline');
ylabel('z^*');
title('Relation between z\_underline and z^*');

Jiiim Wu
Jiiim Wu 2023년 7월 14일
편집: Jiiim Wu 2023년 7월 14일
Hi, thank you for your answer. The code is an economics code. If I want to express z_i follows the uniform distribution from [0,2] and z* is a threshold above which the firm is going to produce. So the z* value is too large. And z_ or underline z is also a value between [0,2]. How to adjust it? So the only random variable is z_i. How do I simulate z*. The price P_i is the price of firm when its productivity is z_i. In other words, there is a continnum of firms in my model. So I have to make sure z* also lies in the range of [0,2] since it is a threshold. Maybe I assume the wrong parameter values.
Moreover, I want to assume that at some range of z aove z*, z_i'=0.7*z_i.For exampe, at the range of [1.2,1.4].z_i' =0.7z_i.
If I assume z_i'=0.7 z_i at the range [1.6,1.8], it has different z*.
Can you help me to put these three curves in one diagram. More than appreciative if you could help me. The attachment are my equations. Thank you so so much.

카테고리

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