# HP Forums

Full Version: composition of functions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a command for the composition of two functions, f and g, in CAS? There is f@@g in xcas, but I do not seem to get it to work in the Prime.
(07-22-2014 01:23 AM)Alberto Candel Wrote: [ -> ]Is there a command for the composition of two functions, f and g, in CAS? There is f@@g in xcas, but I do not seem to get it to work in the Prime.

Try something along the lines of:

f(x):=√(x²-1)
g(x):=4*x

The composition of the two functions is simply:

f(g(x))

HTH
Thank you Mark. But I was looking for something like that on page 12 of this Xcas/giac tutorial
In Xcas, @ does function composition, not @@, @@ is for composition power.
(07-22-2014 09:51 AM)parisse Wrote: [ -> ]In Xcas, @ does function composition, not @@, @@ is for composition power.

Yes, thanks, I should have written f@g for the composition and f@@n for the composite of f with itself n times. The prime accepts f@g, but it seems to return a function like (x,y)->(f(x),g(y)) (if f and g are 1 variable functions).
(07-22-2014 04:07 PM)parisse Wrote: [ -> ]Please give an example.

For instance

f(x):=x^2
g(x):=x+1
f@g returns ((x)->x^2)@((x)->x+1)

I do not know the meaning of @
(07-22-2014 09:14 PM)Alberto Candel Wrote: [ -> ]
(07-22-2014 04:07 PM)parisse Wrote: [ -> ]Please give an example.

For instance

f(x):=x^2
g(x):=x+1
f@g returns ((x)->x^2)@((x)->x+1)

I do not know the meaning of @

The CAS is providing an intermediate solution to the composition.

If you execute:

simplify(f@g)

You get the expected result:

(_(x))->_(x)²+2*_(x)+1
That works, thanks.
But it would be better without the simplify part.

 Actually, if you define k:=f@g, then k(x)=x^2+2*x+1, without the simplify.[/edit]
You can also type (f@g)(x). Note that f@g is a function, not an expression.
(07-23-2014 06:23 PM)parisse Wrote: [ -> ]You can also type (f@g)(x). Note that f@g is a function, not an expression.

Yes, thanks. I think my original mistake was to write f@g(x) instead of (f@g)(x).
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :