error in displaying graph
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
summyia qamar
le 6 Jan 2018
Réponse apportée : Star Strider
le 6 Jan 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/168508/image.jpeg)
0 commentaires
Réponse acceptée
Walter Roberson
le 6 Jan 2018
D and Q are identical and so draw on top of each other.
0 commentaires
Plus de réponses (1)
Star Strider
le 6 Jan 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.
0 commentaires
Voir également
Catégories
En savoir plus sur Price and Analyze Financial Instruments 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!