MathGroup Archive 1998

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

Search the Archive

Re: Problems ....



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



  • Prev by Date: Re: commutativity
  • Next by Date: Re: Extracting polynomial coefficients?
  • Prev by thread: Re: Problems ....
  • Next by thread: Solving Overdetermined Systems