# how to write an expression in ansys

Member Posts: 9

this is an expression for specific heat (CP). Please help me to write an expression for it in Ansys. CP which is used here is a polynomial function of temperature T.

Time = CURRENT_TIME;

for(;;)

{

if(Time<=4.2)

break;

Time=Time-4.2;

}

CP=0;

if(Time<=0.1)

CP=a+b*T+c*T*T+d*T*T*T+e*T*T*T*T;

if(Time<=2.1 && Time>0.1)

CP=f+g*T+h*T*T+i*T*T*T+j*T*T*T*T;

if(Time>2.1 && Time<=2.2)

CP=a+b*T+c*T*T+d*T*T*T+e*T*T*T*T;

if(Time>2.2)

CP=k+l*T+h*T*T+m*T*T*T+n*T*T*T*T;

• Posts: 944Member

make expression called virtual time ...` IF(t<=4.2 [s], 4.2 [s], t- 4.2 [s])`

make an expression called exp_1 .. `1[ J kg^-1 k^-1 ] *(a +b [k^-1] *StaticTemperature +c [k^-2] *StaticTemperature^2+d [k^-3] *StaticTemperature^3+e [k^-4]*StaticTemperature^4)`

same procedure for exp_2 , exp_3 and exp_4

And for Cp use ...` IF( virtual time <= 0.1 [s] , exp_1, IF( virtual time <=2.1, exp_2, IF( virtual time <= 2.2 , exp_3 , exp_4 )))`

• Posts: 39Member

thank you very much @YasserSelima

• Posts: 39Member

it is showing runtime error.

• Posts: 39Member

1[ J kg^-1 K^-1 ] *(a +b [K^-1] *StaticTemperature +c [K^-2] *StaticTemperature**2+d [K^-3] *StaticTemperature**3+e [K^-4]*StaticTemperature**4)

it worked. Btw thanks again

• Posts: 944Member

you are welcome