Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Possible Duplicate:
Best way to extract values from a list of rules?

If I have a vector v = {x->1.03, x-> 2.01, .... }, and I want to use an element in the list, I can get an element as v[[1]] = x-> 1.03 but suppose I want to get rid of the arrow?

Thanks for any suggestions.

share|improve this question
    
x /. v[[1]] ? –  cormullion Jan 28 '13 at 11:15
    
Thanks if you post it as an answer I will upvote and accept. –  daniel Jan 28 '13 at 11:16
1  
there's no hurry :) - the longer you wait, the better the answers become! –  cormullion Jan 28 '13 at 11:17
    
@rm -rf oy, good catch ;-) –  Yves Klett Jan 28 '13 at 15:27
add comment

marked as duplicate by rm -rf Jan 28 '13 at 14:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers

Since ReplaceAll (/.) will only return the first match, i.e.

v = {x -> 1.03, x -> 2.01, x -> 3.02};
w = x /. v

1.03

you could extract all the values considering the FullForm:

FullForm[v]

List[Rule[x, 1.03], Rule[x, 2.01], Rule[x,3.02`]]

w = v[[All, 2]]

{1.03, 2.01, 3.02}

share|improve this answer
    
Table[x /. v[[i]], {i, 1, n}] gave all of them too. –  daniel Jan 28 '13 at 13:22
add comment

I reckon that by "get rid of the arrow" you mean you want to access only the numbers from v. You can achieve that by using

x/.v[[1]]

This applies the first replacement rule given in v to x. You might want to check out Rule and ReplaceAll in the documentation.

share|improve this answer
1  
achive/.achive->achieve... –  einbandi Jan 28 '13 at 11:21
add comment

Not really surprising, but educational: The syntax looks confusing to beginners, but it is very well worth your time to get acquainted with animals like Replace(/.), Rule(->) or Map(/@).

x /. # & /@ {x -> 10, x -> 40}

(*{10, 40} *)

This also works a bit more literally (if not efficently) following your request:

{x -> 10, x -> 40} /. (x -> y_) -> y

(* {10, 40} *)
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.