error in displaying graph

1 visualización (últimos 30 días)
summyia qamar
summyia qamar el 6 de En. de 2018
Respondida: Star Strider el 6 de En. de 2018
I'm solving the following code but the graph is not showing result of "D":
N=10;
D=zeros(1,N); %demand
Q=zeros(1,N); %supply
P=zeros(1,N); %Price
d=1000; %constant of demand function
q=100; %constant of supply function
a=0.8; % sensitivity of demand to price
b=0.5; %sensitivity of supply to price
for t=2:N
P(t)=(d-q-(b*P(t-1)))/a;
D(t)=d-a*P(t);
Q(t)=q+b*P(t-1);
end
%plot
Xvals=1:N;
plot(Xvals,P,'b',Xvals,D,'r',Xvals,Q,'g')
xlabel('time')
legend('Price','Demand','Quantity')
the output is shown below:
however, when i change the *P* function only, the graph appears:
N=10;
D=zeros(1,N); %demand
Q=zeros(1,N); %supply
P=zeros(1,N); %Price
d=1000; %constant of demand function
q=100; %constant of supply function
a=0.8; % sensitivity of demand to price
b=0.5; %sensitivity of supply to price
for t=2:N
P(t)=(P(t-1)-((d-q)/(a+b)))*((-b/a)^t)+((d-q)/(a+b));
D(t)=d-a*P(t);
Q(t)=q+b*P(t-1);
end
%plot
Xvals=1:N;
plot(Xvals,P,'b',Xvals,D,'r',Xvals,Q,'g')
xlabel('time')
legend('Price','Demand','Quantity')
what can be the error? both results show some values of D

Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de En. de 2018
D and Q are identical and so draw on top of each other.

Más respuestas (1)

Star Strider
Star Strider el 6 de En. de 2018
In the first code example:
for t=2:N
P(t)=(d-q-(b*P(t-1)))/a;
D(t)=d-a*P(t);
Q(t)=q+b*P(t-1);
end
both ‘D’ and ‘Q’ have exactly the same values, so ‘Q’ overplots ‘D’.
In the second code example:
for t=2:N
P(t)=(P(t-1)-((d-q)/(a+b)))*((-b/a)^t)+((d-q)/(a+b));
D(t)=d-a*P(t);
Q(t)=q+b*P(t-1);
end
they are not the same, so you see all three.
I leave it to you to determine any error that may be causing that.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by