Technology

Apply a Function to an Array (List): Maxima


One of the things that I always need to do when I use Maxima (the CAS system, not the car) is apply a function to every item in a list (array). Well, here’s how using the map function:

a: [1, 2, 3, 4, 5];
f(x):=x^2;
map(f,a);

Output:
[1,2,3,4,5]
f(x):=x^2
[1,4,9,16,25]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s