geting value as Inf

조회 수: 7 (최근 30일)
MD NASAR
MD NASAR 2012년 5월 9일
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
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 ...

댓글을 달려면 로그인하십시오.

채택된 답변

Kevin Holst
Kevin Holst 2012년 5월 9일
Here's what I think your code should look like in order to run properly:
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);
q = 0.8*ones(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-1
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(xxx)=n*q(xxx)^(x(xxx)-1)+c0;
disp('c(t)');
c(xxx)
p(xxx)=c(xxx)-lembda(xxx)+1/d;
disp('p(t)');
p(xxx)
a(xxx)=(p(xxx)-c(xxx)+lembda(xxx))*beta*(M-x(xxx))*exp(-d*p(xxx))*exp(h*q(xxx));
disp('a(t)');
a(xxx)
end
Note that I took q(t) out of the loop. It's really just a constant so you shouldn't even have it as a vector. This still gives me infs after a few iterations, but that's just because you're raising a number to a VERY large number (0.8^-1.33E39). You're also taking the log10 of a negative number in there so you may want to switch all of your log10(a(t)) commands to log10(abs(a(t))).
  댓글 수: 3
Kevin Holst
Kevin Holst 2012년 5월 9일
you're welcome
MD NASAR
MD NASAR 2012년 5월 10일
Sir in this program i want to solve this equations using genetic algorithm, and i will give only initial value of x and lembda ie x(1) and lembda(1). on the base of this 2 values he can find value of p(t),c(t),a(t) and q(t). how i will do this if u have any idea please tell me, i am waiting for ur positive response.
Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Kevin Holst
Kevin Holst 2012년 5월 9일
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
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
MD NASAR 2012년 5월 9일
Sir thank you so much. from this code first i want to calculate x(t+1), lembda(t+1),c(t),p(t),a(t)
from x(t+1) i will get value of x(2)and from lembda(t+1) will get lembda(2) from this value i will get the value of c(2),p(2),a(2) like that and i want all value from 1 to 20.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by