Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Possible Duplicate:
Composition of mappings not working as expected

I am new to Mathematica and I am having trouble defining a certain composition of functions.

Let m1 and m2 be maps such that $m_1: \mathbb{R}^2 \to \mathbb{R}^2$ and $m_2: \mathbb{R}^2 \to \mathbb{R}^2$ where $\mathbb{R}$ is the real line

m1[eta_, zeta_] = {eta^3, zeta^3} 
m2[x_, y_] = x^2 + y^2

m3[eta_, zeta_]  = Composition[m2, m1][eta, zeta]

On evaluating the last line, I get the output

(* m2[{eta^3, zeta^3}] *)

But the anwer to this should be m3[eta,zeta]=eta^6 + zeta^6

How can I do this?

share|improve this question

marked as duplicate by Artes, Brett Champion, Leonid Shifrin, Simon Woods, rm -rf Jan 10 '13 at 17:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
m3[eta_, zeta_] = m2 @@ m1[eta, zeta] see documentation about Apply –  ssch Jan 10 '13 at 15:36
    
Composition is only meaningful for single-argument functions. Make your functions take a single list-argument instead of several scalar arguments. –  Szabolcs Jan 10 '13 at 15:44
add comment

2 Answers 2

If your m1 function outputs a list of 2 values, your m2 function should take that as input. Makes sense, right?

m1[eta_, zeta_] = {eta^3, zeta^3}
m2[{x_, y_}] = x^2 + y^2

Otherwise, make it return a Sequence

m1[eta_, zeta_] = Sequence[eta^3, zeta^3]
m2[x_, y_] = x^2 + y^2

Now

m3[eta_, zeta_] = Composition[m2, m1][eta, zeta]

(*eta^6 + zeta^6*)
share|improve this answer
    
but then why shouldn't m1 take a list of 2 values, too? –  Rolf Mertig Jan 10 '13 at 16:12
    
@RolfMertig I agree, both getting a list may be a cleaner design –  Rojo Jan 10 '13 at 16:47
add comment

Maybe this is clearer? :

m1[{eta_,zeta_}]={eta^3,zeta^3};
m2[{x_,y_}]=x^2+y^2;
m3[{eta_,zeta_}]=Composition[m2,m1][{eta,zeta}]
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.