MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: using predefined expressions in functions [newbie question]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg100219] Re: using predefined expressions in functions [newbie question]
  • From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
  • Date: Thu, 28 May 2009 06:49:51 -0400 (EDT)

Hi, ChangMo,

Try to determine the function explicitly in terms of its arguments like one of the following:


f1[R1_, R2_] := R1.R2;

In[17]:= f1[{1, 2, 3}, {4, 5, 6}]

Out[17]= 32

or otherwise,

f2[x1_, y1_, z1_, x2_, y2_, z2_] := x1*x2 + y1*y2 + z1*z2;

In[25]:= f[1, 2, 3, 4, 5, 6]

Out[25]= 32

or like this:

In[35]:= 
f[x1_, y1_, z1_, x2_, y2_, z2_] := {x1, y1, z1}.{x2, y2, z2};

f[1, 2, 3, 4, 5, 6]

Out[36]= 32

Hi,

I've been trying to write a function using some predefined
expressions, but the function assignment seems to understand the
symbols in the expressions as literals. eg.,

Needs["VectorAnalysis`"]
R1 := {x1,y1,z1}
R2 := {x2,y2,z2}
f[x1_,y1_,z1_,x2_,y2_,z2_] := R1 . R2

f[1,2,3,4,5,6]

gives the output
x1 x2 + y1 y2 + z1 z2
instead of
32 ( = 1*4 + 2*5 + 3*6 )

Can anyone help me with this?  Thanks for your attention.


-ChangMo


-- 
Alexei Boulbitch, Dr., habil.
Senior Scientist

IEE S.A.
ZAE Weiergewan
11, rue Edmond Reuter
L-5326 Contern
Luxembourg

Phone: +352 2454 2566
Fax:   +352 2454 3566

Website: www.iee.lu

This e-mail may contain trade secrets or privileged, undisclosed or otherwise confidential information. If you are not the intended recipient and have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal from your system. Thank you for your co-operation.




  • Prev by Date: Re: Working with Indeterminate in large numerical lists
  • Next by Date: Re: simultaneous equations for chemical speciation
  • Previous by thread: Re: using predefined expressions in functions [newbie question]
  • Next by thread: constants