Re: Problems ....
- To: mathgroup@smc.vnet.net
- Subject: [mg11559] Re: [mg11532] Problems ....
- From: Sean Ross <seanross@worldnet.att.net>
- Date: Sat, 14 Mar 1998 13:56:12 -0500
- References: <199803131722.MAA03809@smc.vnet.net.>
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. > > 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 > > thanks. 1. I am confused by X and Y. What does Y have to do with this question? If you want to replace a symbol or number with another in an expression, use a transformation rule. X/.a->b 2. Sort[X] you can change the criteria by which the sort occurs by using the option p. Using this option usually requires the use of "pure functions" as in Sort[x,If[#1>#2,True,False]&], where the second argument gives a true if the elements as sorted in descending order and false otherwise. The net effect of this sorting function is to sort in reverse order. Sort[{1,3,4,5,8,2},If[#1>#2,True,False]&] returns {8,5,4,3,2,1} while Sort[{1,3,4,5,8,2},If[#1<#2,True,False]&] or Sort[{1,3,4,5,8,2}] returns {1,2,3,4,5,8} 3. If x is a 1-D list, y = x^2 * Sign[x] 4. Drop[x,{2}] Finally, a comment. From your questions, it is clear you are just starting to become familiar with the language and your programming will be seriously hampered without a basic knowledge of the features of mathematica and you will have to wait 2 days for someone to answer your question via mathgroup. If you have not done so, I recommend you purchase a hard copy of the mathematica book and fall asleep a few nights in a row looking through it just to see what is out there. At least go through all the examples in the "tour of mathematica" section. You have some potentially dangerous concepts implicit in your questions, such as calling a 1-D list a vector. You may think of them as vectors or may use them to represent vectors, but without special handling, 1-D lists don't multiply, transform or behave like vectors. Another concept is "arbitrary numerical vector". There is no such thing in mathematica. You can have a symbol with or without assigned values. You can make a list composed of symbols which have not been assigned values yet, but you cannot tell mathematica that something is a list without putting something in the elements of said list.(If I am wrong on this point, somebody please tell me how to do it) If a list is arbitrary, it is not yet numeric. If it has been assigned numbers to its elements it is no longer arbitrary. Good luck. -- Remove the _nospam_ in the return address to respond.
- References:
- Problems ....
- From: tie@cscn.com (Tie)
- Problems ....