Please help to correct my code
23 次查看(过去 30 天)
显示 更早的评论
% 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
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?
回答(2 个)
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^*');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
