Why is matlab not computing this correctly?

How is it that matlab does not calculate this correctly. I do not understand. what am I doing wrong here?
for T=295.45
c0=0.99999683;
c1=-0.90826951*10^(-2);
c2=0.78736169*10^(-4);
c3=-0.61117958*10^(-6);
c4=0.43884187*10^(-8);
c5=-0.29883885*10^(-10);
c6=0.21874425*10^(-12);
c7=-0.17892321*10^(-14);
c8=0.11112018*10^(-16);
c9=-0.30994571*10^(-19);
E=(c0+T*(c1+T*(c2+T*(c3+T*(c4+T*(c5+T*(c6+T*(c7+T*(c8+T*(c9))))))))));
end
the answer answer should be E=0.8308! but why is matlab giving me -137.0354? I got the correct answer by copying and pasting the same code into a different program..any help?

댓글 수: 2

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 24일
What do you mean by different program?
dpb
dpb 2013년 10월 24일
Excel??? :)

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

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 24일
편집: Azzi Abdelmalek 2013년 10월 24일

0 개 추천

Why are you expecting 0.8308? the correct answer is -137.0354, you can find it with the for loop:
v=[c9,c8,c7,c6,c5,c4,c3,c2,c1,c0];
E=0;
for k=1:numel(v)-1
E=(E+v(k))*T;
end
E=E+v(end)
dpb
dpb 2013년 10월 24일

0 개 추천

I'm guessing because you're evaluating the correlation for the wrong T -- generally these are either reduced temperatures or differentials -- let's see
>> T0=295.45;
>> T=T0-273.15;
>> E=(c0+T*(c1+T*(c2+T*(c3+T*(c4+T*(c5+T*(c6+T*(c7+T*(c8+T*(c9))))))))))
E =
0.8308
>>
That look more better????
Just for checkin'...
>> T=T0/273.15;
>> E=(c0+T*(c1+T*(c2+T*(c3+T*(c4+T*(c5+T*(c6+T*(c7+T*(c8+T*(c9))))))))))
E =
0.9903
>>
Ay-yup, looks like differential from reference not reduced presuming your other evaluation is the correct answer, of course! :)

댓글 수: 1

Armel
Armel 2013년 10월 24일
You are absolutely right..my Temperature T shouldn't have been in Kelvin but in celsius! so T=295.45K = 22.3C. I should have used 22.3 for the matlab..for whatever reasons I overlooked that. Thanks

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

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

태그

아직 태그를 입력하지 않았습니다.

질문:

2013년 10월 24일

댓글:

2013년 10월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by