# [Maxima] itensor and vector norm (?)

Rupert Swarbrick rswarbrick at gmail.com
Sun May 20 17:16:52 CDT 2012

```Gabrijela Grgača <gaby-g at live.com> writes:
> I start using Maxima 2 day's ago, so I'm having one maybe trival difficult.
>
> For my Math project one of the tasks is to caluculate vector 1norm,
> 2norm, and infinity norm in Maxima, and vectors are:
>
> X=(1,-3), Y=(1,8,-5),  Z=(3,-5,0,-9)
>
> So any kind of help or suggestion would help a lot
>
> Gambrinus

Hi,

I'm going to answer the 1-norm question, but you'll have to do the
others. After all, the project presumably expected you to work out how
to do this yourself. Also, you say you have to do it in Maxima. This is
lovely news, but surprising: what course are you taking and where?

The 1-norm you're talking about is presumably the sum of the absolute
values of the coordinates of the vector. As such, you're going to need
the absolute value function. Fortunately, it maps over lists
automatically:

(%i1) abs([-3, 2]);
(%o1)                               [3, 2]

Ahah! Now you just need to sum the elements of the resulting
list. There's a function called lsum that'll do that for you:

(%i2) lsum(x, x, abs([-3, 2]));
(%o2)                                  5

"But what is this repeated x?", I hear you ask. Well, check the manual
and you'll see that lsum sums a given expression over the elements of
the list. For example,

(%i3) lsum(abs(x), x, [-3, 2]);
(%o3)                                  5

gives you the same answer. You can package the result up as a function
as follows:

(%i4) one_norm (v) := lsum(abs(x), x, v);
(%o4)                  one_norm(v) := lsum(abs(x), x, v)
(%i5) one_norm ([1,-3]);
(%o5)                                  4

Now try to work out how to do the 2-norm (or indeed the p-norm for any
p). For the infinity norm, you'll have to think of a slight

Rupert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 315 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20120520/e98c3058/attachment.pgp>
```