MATLAB Answers

I need a help on making the number calculation into matrix calculation

1 view (last 30 days)
Yutong Wu
Yutong Wu on 19 Oct 2020
Answered: Ameer Hamza on 19 Oct 2020
clc;
clear all;
Profit_S_B = [];
Profit_S_Q = [];
Profit_S_R =[];
Q1 = 100;
q_01 = 50;
P_r = 400;
c = 20;
g = 50;
x = norminv(g/(g+c),100,30);
theta = 0.8351;
Ps_B = ((1-theta)*P_r*g+P_r*c-c*c)/(g+c);
Ps_Q = (P_r*c-c*c)/(g+c);
Ps_R = (theta*P_r*c-c*c)/(g+c);
D =150; % Here if I want change D into For D =1:1:300
S_N0 = min(x,D);
I_N0 = max(0,(D-x));
S_L0 = min((D-S_N0),(Q1+q_01-x));
I_L0 = max(0,(D-Q1-q_01));
Profit_S_B = Ps_B*x + (1-theta)*P_r*S_N0 + (P_r-c)*S_L0 - I_L0*g-(1-theta)*P_r*x
Profit_S_Q =Ps_Q*x + (P_r-c).*S_L0-I_L0*g
Profit_S_R =Ps_R*x+(1-theta)*P_r*S_N0+(P_r-c).*S_L0-I_L0*g
Here If I want Change D = 150 to For D = 1:1:300, How should I change the folloing code?

  0 Comments

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 19 Oct 2020
clc;
clear all;
Profit_S_B = [];
Profit_S_Q = [];
Profit_S_R =[];
Q1 = 100;
q_01 = 50;
P_r = 400;
c = 20;
g = 50;
x = norminv(g/(g+c),100,30);
theta = 0.8351;
Ps_B = ((1-theta)*P_r*g+P_r*c-c*c)/(g+c);
Ps_Q = (P_r*c-c*c)/(g+c);
Ps_R = (theta*P_r*c-c*c)/(g+c);
D = 1:300;
S_N0 = zeros(size(D));
I_N0 = zeros(size(D));
S_L0 = zeros(size(D));
I_L0 = zeros(size(D));
Profit_S_B = zeros(size(D));
Profit_S_Q = zeros(size(D));
Profit_S_R = zeros(size(D));
for i = 1:numel(D)
S_N0(i) = min(x,D(i));
I_N0(i) = max(0,(D(i)-x));
S_L0(i) = min((D(i)-S_N0(i)),(Q1+q_01-x));
I_L0(i) = max(0,(D(i)-Q1-q_01));
Profit_S_B(i) = Ps_B*x + (1-theta)*P_r*S_N0(i) + (P_r-c)*S_L0(i) - I_L0(i)*g-(1-theta)*P_r*x;
Profit_S_Q(i) =Ps_Q*x + (P_r-c).*S_L0(i)-I_L0(i)*g;
Profit_S_R(i) =Ps_R*x+(1-theta)*P_r*S_N0(i)+(P_r-c).*S_L0(i)-I_L0(i)*g;
end

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by