[Date Index]
[Thread Index]
[Author Index]
Re: How to define a polyfunction?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg27421] Re: How to define a polyfunction?
*From*: "Allan Hayes" <hay at haystack.demon.co.uk>
*Date*: Sun, 25 Feb 2001 00:53:48 -0500 (EST)
*References*: <974vp8$6jh@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
Liwen,
You get,
golf=t^2-t;
Key[t_]:=If[(D[golf[t],t]>0),(t^4+t*3),(t^2.5-t)];
Key[2]
General::ivar: 2 is not a valid variable.
If[D[(-t + t^2)[2], 2] > 0, 2^4 + 2*3, 2^2.5 - 2]
Two problems:
a) 2 is passed to the right giving D[golf[2],2], which makes no sense
b) golf is not a function, so even golf[2]] would not work as you would like
We also need to consider the possible effect of an of t having a value when
golf and Key are defined or when Key is used.
golf[2]
\!\(\((\(-t\) + t\^2)\)[2]\)
Some suggestions
Following b)
Define a function golf; use its derivative, golf', use SetDelayed, :=,
Clear["`*"]
t=3;
golf[t_]:=t^2-t;
Key[t_]:=If[(golf'[t]>0),(t^4+t*3),(t^2.5-t)];
Key[2]
22
Following a)
Separate the two roles of t; use SetDelayed and Block
Clear["`*"]
t=3;
golf:=t^2-t;
Key[s_]:=
Block[{t},
If[(D[golf,t]/.t\[Rule]s )>0,(s^4+s*3),(s^2.5-s)]
];
Key[2]
22
Similarly
Clear["`*"]
t=3;
golf:=t^2-t;
Key[s_]:=
Block[{t},
If[D[golf,t]>0,(#^4+#*3),(#^2.5-#)]&[s]
]
Key[2]
22
and thirdly,
Clear["`*"]
t=3;
golf:=t^2-t;
Key[s_]:= Block[{ t=s},
Block[{t},
If[D[golf,t]>0,(s^4+s*3),(s^2.5-s)]
]
];
Key[2]
22
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"liwen liwen" <gzgear at yahoo.com> wrote in message
news:974vp8$6jh at smc.vnet.net...
> Dear friend,
> How are you!Now I encounter a problem that I
> can not solve for a long time .
> It can be express simplely as how to define a
> polyfunction,for example,a simple polyfunction may be
> defined as that:
>
> Key[t_]:=If[(t>0),1,0];
>
> It is easy to define.However,it will be more difficult
> when the condition turns more complicate.For instance:
> golf=t^2-t;
> Key[t_]:=If[(D[golf[t],t]>0),(t^4+t*3),(t^2.5-t)];
>
>
> Best regards,
>
>
> Liwen
> E-mail: gzgear at yahoo.com
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - Buy the things you want at great prices!
http://auctions.yahoo.com/
>
Prev by Date:
**Re: Extracting units from a list of values**
Next by Date:
**Re: Extracting units from a list of values**
Previous by thread:
**Re: Re:How to define a polyfunction?**
Next by thread:
**Integration problem**
| |