Functions in Compose

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Hello,

 

I was having an issue when using functions in Compose. I would like to explain the issue with a simple example as shown below.

 

I created the function below in Compose:

 

function [a,b,c,d] = trial1(x,y,z)
    a=2; b=5; c=x+y; d=x/a;
end

 

I saved the file with the name 'trial1.oml'

 

Then, in the command window, I typed 

 

 [a,b,c,d] = trial1(6,12,20)

 

Compose returned the following results as expected:

 

a = 2
b = 60
c = 18
d = 3

 

Then, I modified the function as follows and I saved the file:

 

function [a,b,c,d] = trial1(x,y,z)
    a=x+z; b=y*z; c=x+y; d=x/a;
end

 

Please note that the expression for outputs a and b have changed. According to the new function, a should be 26 and b should be 240. The I run the same line in the command window:

 

[a,b,c,d] = trial1(6,12,20)

 

And I get the following results:

 

a = 2
b = 60
c = 18
d = 3

 

which are the same as the previous ones. When I restart compose and run the same line in the command window, I get the right results for the updated function. 

 

a = 26
b = 240
c = 18
d = 0.230769231

 

It seems like the changes I make in the function do not take place immediately. Could you please help me with this?

 

Thank you

Berker

 

Tagged:

Answers

  • manoj kandukuri
    manoj kandukuri
    Altair Employee
    edited February 2021

    Hi Berker,

    Once you execute the function/script, function name will be stored in the memory space until you clear the memory associated with the function or you close & re- open a new instance and evaluate the function.  When you edited the file and saved it, the function name is still in memory (from previous evaluation), so when evaluated its taking the previous statements.

     

    Please do 'clear trail1' before evaluating the function for 2nd time.   see below. 

     

    [a,b,c,d] = trial1(6,12,20)

    a = 2

    b = 5

    c = 18

    d = 3

    > clear trial1

    > [a,b,c,d] = trial1(6,12,20)

    a = 26

    b = 240

    c = 18

    d = 0.230769231

     

    thanks,

    Manoj