geting value as Inf
이전 댓글 표시
Dear All
i am solving a equation after first iteration i got value as infinity, actually i want the value of x(1)to x(20), Lembda(1) to Lembda(2), c(1) to c(20), P(1)to p(20) and a(1) to a(20). when i am running code only i am able to get the value of first iteration. after first iteration x(2) value become inf. here is the code.
M=100;
r=0.8;
alpha=0.45;
beta=0.75;
gama=0.1;
d=0.004;
h=0.4;
n=100;
c0=1500;
nn=10;
x = zeros(nn,1);
a = zeros(nn,1);
p = zeros(nn,1);
c = zeros(nn,1);
lembda = zeros(nn,1);
delT=1;
c(1)=1580;
x(1)=2;
a(1)=310000;
p(1)=1635;
lembda(1)=150;
for t=1:nn
q(t)=0.8;
xxx=t+1;
x(xxx)=x(t)+delT*alpha+beta*log10(a(t))+gama*x(t)*(M-x(t))*exp(-d*p(t))*exp(h*q(t));
disp('x(t)');
x(xxx)
gx=exp(-d*p(t))*exp(h*q(t))*(gama*M-alpha-beta*log10(a(t))-2*gama*x(t));
cx=n*q(t)^(x(t)-1)*log10(q(t));
gt=(alpha+beta*log10(a(t))+gama*x(t))*(M-x(t))*exp(-d*p(t))*exp(h*q(t));
lembda(xxx)=lembda(t)+delT*(r*lembda(t)-gx*(p(t)-c(t)+lembda(t))+cx*gt);
disp('lembda(t+1)');
lembda(xxx)
c(t)=n*q(t)^(x(t)-1)+c0;
disp('c(t)');
c(t)
p(t)=c(t)-lembda(t)+1/d;
disp('p(t)');
p(t)
a(t)=(p(t)-c(t)+lembda(t))*beta*(M-x(t))*exp(-d*p(t))*exp(h*q(t));
disp('a(t)');
a(t)
end
please help me to get my desired result.
Thank You
댓글 수: 1
Daniel Shub
2012년 5월 9일
While we all appreciate the formatting of the code, when you deleted your previous question, you deleted my answer. This new "question" isn't actually a question, but rather a command. Further, the concept of your desired result, is confusing ...
채택된 답변
추가 답변 (1개)
Kevin Holst
2012년 5월 9일
0 개 추천
I actually answered your problem in your previous problem. The error is in your calculations for c, p, and specifically a. These values get calculated and then are placed in the 't' index rather than the 'xxx' ('t+1') index. As a result, when your loop goes through for the second time, you take log10(a(t)) which is log10(0), resulting in -inf. That -inf then cascades into your other calculations.
댓글 수: 2
Kevin Holst
2012년 5월 9일
Since I don't actually know what these equations mean or what they're supposed to be doing, I can't give you an exact solution to your problem. However, my answer points out where your error lies.
MD NASAR
2012년 5월 9일
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!