Receiving non-integer number results on a matrix model code

조회 수: 15 (최근 30일)
Sabrina
Sabrina 2014년 1월 20일
댓글: Sabrina 2014년 1월 25일
Hello, everyone.
First, I would like to state that I am something of a coding idiot. If we were in person, I would ask you to speak slowly and loudly, but this is the internet, so I instead ask your patience if my question is seemingly obvious.
I'm also probably posting what is an annoying amount of code, but I have no clue where the problem lies, so I want to provide as much information as possible.
Here is the code I am trying to run. I have put '###' around the two troublesome lines:
meanvr = [.56552 0.195165 2.835 .5500];
vrhi = [.861332 0.250000 3.000 .41844];
vrlo = [.405612 0.175165 2.755 .37063];
syms AS JS Fe Pf
Svr = [AS JS Fe Pf];
mx = [0, JS*Fe*Pf;
JS, AS];
reps=500;
rand('state',sum(100*clock));
numvrs = length(meanvr);
allvrs = rand(reps,numvrs);
allvrs = allvrs.*repmat(vrhi-vrlo,reps,1) + repmat(vrlo,reps,1);
for rr = 1:reps
disp(rr);
realmx=subs(mx,Svr,allvrs(rr,:));
[lambdas,lambda1,W,w,V,v]=eigenall(realmx);
sensmx=v*w'/(v'*w);
elastmx=(sensmx.*realmx)/lambda1;
alllams(rr,1)=lambda1;
for xx=1:numvrs
diffofvr=subs(diff(mx,Svr(xx)),Svr,allvrs(rr,:));
vrsens(xx)=sum(sum(sensmx.*diffofvr));
end;
allelasts(rr,:)=((vrsens.*allvrs(rr,:))/lambda1);
end;
realmx=subs(mx,Svr,meanvr);
[lambdas,lambda1,W,w,V,v]=eigenall(realmx);
meanlam1=lambda1; sensmx=v*w'/(v'*w);
elastmx=(sensmx.*realmx)/lambda1;
meansens = zeros(1,numvrs);
for xx = 1: numvrs
diffofvr=subs(diff(mx,Svr(xx)),Svr,meanvr);
meansens(xx) = sum(sum(sensmx.*diffofvr));
end;
meanelast=((meansens.*meanvr)/lambda1);
maxlams=zeros(1,numvrs);
for rate = 1:numvrs
vrates=meanvr; vrates(rate)=vrhi(rate);
realmx=subs(mx,Svr,vrates);
[lambdas,lambda1,W,w,V,v]=eigenall(realmx);
maxlams(rate)=lambda1;
end;
disp('Below are the maximum lambdas and max proportional')
disp('change in lambdas from changing each vital rate')
disp(Svr); disp(maxlams)
###disp((maxlams-ones(1,numvrs)*meanlam1)/meanlam1)###
disp('Below are the x^2 values for lambda and each')
disp('vital rate, a measure of influence on population')
disp('growth for the random simulated matrices')
correls=corrcoef(double([allvrs, alllams]));
disp(Svr); disp((correls(numvrs+1,1:numvrs)).^2);
disp('Below are the elasticities for the mean vital rates,')
disp('and then the min, max, mean, and st. deviation of the')
disp('elasticity values from the random matrices')
###disp(Svr); disp(meanelast);###
disp(min(double(allelasts))); disp(max(double(allelasts)));
disp(mean(double(allelasts))); disp(std(double(allelasts)));
However, when I run the code, I get very odd numbers as results for those two troublesome lines. For example, the first row of numbers is what I would expect, but the second is... well:
Below are the maximum lambdas and max proportional
change in lambdas from changing each vital rate
[ AS, JS, Fe, Pf]
0.9255 0.7040 0.6606 0.6365
[ -(113049347475759065049474359227755610434514^(1/2)/900719925474099200000 - 9045809355840329847/14073748835532800000)/(113049347475759065049474359227755610434514^(1/2)/900719925474099200000 + 7069/25000), -(113049347475759065049474359227755610434514^(1/2)/900719925474099200000 - 92622050966827273/219902325555200000)/(113049347475759065049474359227755610434514^(1/2)/900719925474099200000 + 7069/25000), -(113049347475759065049474359227755610434514^(1/2)/900719925474099200000 - 5318325929310998597/14073748835532800000)/(113049347475759065049474359227755610434514^(1/2)/900719925474099200000 + 7069/25000), -(113049347475759065049474359227755610434514^(1/2)/900719925474099200000 - 4978563237831842347/14073748835532800000)/(113049347475759065049474359227755610434514^(1/2)/900719925474099200000 + 7069/25000)]
Any help anyone is willing to give is much appreciated.

채택된 답변

Walter Roberson
Walter Roberson 2014년 1월 20일
disp(double(meanelast))
  댓글 수: 1
Sabrina
Sabrina 2014년 1월 25일
After last time, I should have known to try that! Thank you so much, again.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by