error in displaying graph
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
更多回答(1 个)
Star Strider
2018-1-6
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Price and Analyze Financial Instruments 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!