Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Numerical calculation error using eval

조회 수: 5 (최근 30일)
Mike
Mike 2012년 3월 6일
마감: MATLAB Answer Bot 2021년 8월 20일
I'm going through a calculation to convert RH to dewpoint, and for the first step I need to get the saturation vapor pressure, es.
es=eval(['6.11*exp(((Lv*Mw)/R)*((1/273)-(1./temp_ruc_',eventlist(z,:),')));']);
The error occurs within the exponent term...
I evaluated (Lv*Mw/R) and ((1/273)-(1./temp_ruc_',eventlist(z,:),')) separately, and both work.
I also tried the whole term using a sample temperature value (290 K), and I got the right answer:
((Lv*Mw)/R)*((1/273)-(1/290)) = 1.1632e+03
Given the range of temp values, all the answers should be in this range... But when I go through the calculation in full, as shown below, I get values ranging from -6 to +2...
eval(['((Lv*Mw)/R)*((1/273)-(1./temp_ruc_',eventlist(z,:),'))'])
What could be causing this error?
  댓글 수: 1
Jan
Jan 2012년 3월 7일
Avoid EVAL. It provokes errors and problems - obviously. And there is always a better solution.

답변 (1개)

Walter Roberson
Walter Roberson 2012년 3월 6일

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by