Please help to correct my code
Ältere Kommentare anzeigen
% 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 Kommentare
Dyuman Joshi
am 14 Jul. 2023
"And z_ or underline z is also a value between [0,2]. How to adjust it?"
You have define z_ between 0.1 and 1. Just change the values.
%Adjust the values
z_underline = linspace(0, 2, num_points);
"How do I simulate z*."
I do not understand what you mean by this. Please clarify.
Jiiim Wu
am 14 Jul. 2023
Dyuman Joshi
am 14 Jul. 2023
"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
am 14 Jul. 2023
Antworten (2)
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^*');
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
