Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #15100 > unrolled thread
| Started by | Joaquim Nogueira <jen@fct.unl.pt> |
|---|---|
| First post | 2013-07-03 08:49 +0000 |
| Last post | 2013-07-03 22:06 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Define function using lists or tables Joaquim Nogueira <jen@fct.unl.pt> - 2013-07-03 08:49 +0000
Re: Define function using lists or tables "Nasser M. Abbasi" <nma@12000.org> - 2013-07-03 22:06 +0000
| From | Joaquim Nogueira <jen@fct.unl.pt> |
|---|---|
| Date | 2013-07-03 08:49 +0000 |
| Subject | Define function using lists or tables |
| Message-ID | <kr0oij$3dv$1@smc.vnet.net> |
Hello. Possibly this is a very simple question.
Is there a way to define a function over a (BIG) list of ordered pairs? I mean, suppose that I have a list, created using a Table command or something like that, of the form [{a,b},{c,d},etc.] such that, after naming it f, say, f = [{a,b},{c,d},etc.], then, afterwards, whenever there is a command such that one needs to compute f[a] (or f[c]), the program immediately replaces f[a] by b,and f[c] by d?
Thank you.
[toc] | [next] | [standalone]
| From | "Nasser M. Abbasi" <nma@12000.org> |
|---|---|
| Date | 2013-07-03 22:06 +0000 |
| Message-ID | <kr278a$8uu$1@smc.vnet.net> |
| In reply to | #15100 |
On 7/3/2013 3:49 AM, Joaquim Nogueira wrote:
> Hello. Possibly this is a very simple question.
>
> Is there a way to define a function over a (BIG) list of ordered pairs? I mean,
>suppose that I have a list, created using a Table command or something like that,
>of the form [{a,b},{c,d},etc.] such that, after naming it f, say,
>f = [{a,b},{c,d},etc.], then, afterwards, whenever there is a command such
>that one needs to compute f[a] (or f[c]), the program immediately replaces f[a] by b,and f[c] by d?
>
> Thank you.
>
This looks like a hash table. In Mathematica, it is build in. All what
you have to do is:
--------------
f[a] = b;
f[c] = d;
-------------
Now
---------------------
In[294]:= f[a]
Out[294]= b
--------------------
There are more advanced ways to do this for more complicated setups.
google the subject of hash tables with mathematica for more information.
--Nasser
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web