MathGroup Archive 1998

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

Search the Archive

Re: Problems ....



Hi:

The answers to your questions are as follows:

Tie wrote:

> I am a new user. need help to know more about mathematica. 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.

In:
x={1,3,-5,3,-4};
y={3,8};

x=x /. y[[1]]->y[[2]]


Out:
{1,8,-5,8,-4}

> 2. Sort the elements of X in ascending order of absolute value.

In:x={1,3,-5,3,-4};
x=Sort[x,Abs[#1]<Abs[#2]&]

Out:
{1,3,3,-4,-5}

>
>
> 3. Square each elements of a vector X but keep its sign.

In:x={1,3,-5,3,-4};
x=Map[Sign[#] #^2 &,x]

Out:
{1,9,-25,9,-16}

>
>
> 4. Remove second element of the vector X without using the Table
> function
>

In:x={1,3,-5,3,-4};
x=Drop[x,{2}]

Out:
{1,-5,3,-4}

> thanks.

  Cheers,

--
Des Penny
Physical Science Dept.
Southern Utah University
Cedar City, UT 84720

Office: (435) 586-7708
FAX:  (435) 865-8051
email: penny@suu.edu

Home: (435) 586-2286
email: dpenny@iname.com




  • Prev by Date: Re: Two questions
  • Next by Date: Re: making MatrixForm[] defaul
  • Prev by thread: Re: Problems ....
  • Next by thread: Re: Problems ....