Please help to correct my code
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% 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 commentaires
Dyuman Joshi
le 14 Juil 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?
Réponses (2)
Dyuman Joshi
le 14 Juil 2023
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 commentaires
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
