Previous Up Next

2.16.6  Define a fonction with the history : as_function_of

If an entry defined the variable a and if in a later entry defines the variable b (supposed to be dependant on a), then c:=as_function_of(b,a) will define a function c such that c(a)=b.
Input :

a:=sin(x)

Output :

sin(x)

Input :

b:=sqrt(1+a^2)

Output :

sqrt(1+sin(x)^2)

Input :

c:=as_function_of(b,a)

Output :

(a)->
{ local NULL;
return(sqrt(1+a
^2));
}

Input :

c(x)

Output :

sqrt(1+x^2)

Input :

a:=2

Output :

2

Input :

b:=1+a^2

Output :

5

Input :

c:=as_function_of(b,a)

Output :

(a)->
{ local NULL;
return(sqrt(1+a
^2));
}

Input :

c(x)

Output :

1+x^2

Warning !!
If the variable b has been assigned several times, the first affectation of b following the last affectation of a will be used. Moreover, the order used is the order of validation of the commandlines, which may not be reflected by the Xcas interface if you reused previous commandlines.
Input for example :
a:=2 then
b:=2*a+1 then
b:=3*a+2 then
c:=as_function_of(b,a)
Output :

(a)-> {local NULL; return(2*a+1);}

i.e. c(x) is equal to 2*x+1.
But, input :
a:=2 then
b:=2*a+1 then
a:=2 then
b:=3*a+2 then
c:=as_function_of(b,a)
Output :

(a)-> {local NULL; return(3*a+2);}

i.e. c(x) is equal to 3*x+2.
Hence the line where a is define must be revalided before the good definition of b.


Previous Up Next