Re: Problems ....
- To: mathgroup@smc.vnet.net
- Subject: [mg11585] Re: Problems ....
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Date: Tue, 17 Mar 1998 10:43:06 -0500
- References: <6ecfs2$5ba@smc.vnet.net>
Tie wrote: > Anyone can > help me do the following: > > 1. Let Y={a,b} and let X be an arbitrary numeric vector. Replace all > occurances of a in X with b. > > 2. Sort the elements of X in ascending order of absolute value. > > 3. Square each elements of a vector X but keep its sign. > > 4. Remove second element of the vector X without using the Table > function Tie: Y= {2,-1}; X = {-3,2,5,2} {-3,2,5,2} 1) X/.Rule@@Y (*Rule@@Y gives 2->-1*) {-3,-1,5,-1} 2) Sort[X, Abs[#]<=Abs[#2]&] {2,2,-3,5} 3) X X Sign[X] {-9,4,25,4} 4) Drop[X,{2}] {-3,5,2} -- Allan Hayes Training and Consulting Leicester, UK hay@haystack.demon.co.uk http://www.haystack.demon.co.uk voice: +44 (0)116 271 4198 fax: +44 (0)116 271 8642