Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8184 > unrolled thread

Re: calculating with vectors of variable length

Started byUlrich Arndt <ulrich.arndt@data2knowledge.de>
First post2012-01-26 08:31 +0000
Last post2012-01-26 08:31 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: calculating with vectors of variable length Ulrich Arndt <ulrich.arndt@data2knowledge.de> - 2012-01-26 08:31 +0000

#8184 — Re: calculating with vectors of variable length

FromUlrich Arndt <ulrich.arndt@data2knowledge.de>
Date2012-01-26 08:31 +0000
SubjectRe: calculating with vectors of variable length
Message-ID<jfr315$nin$1@smc.vnet.net>
this should work if a and x should be in variable length and giving as input parameters.

Clear[f]
f::nonequallength =
  "The argument `1` and `2` do not have the same length.";
f[x_?VectorQ, a_?VectorQ] :=
 If[Length[a] == Length[x], a.x, Message[f::nonequallength, x, a]]

f[{1, 2, 3}, {a1, a2, a3}]
f[{b1, b2, b3, b4}, {a1, a2, a3, a4}]
f[{b1, b2, b3, b4}, {a1, a2, a3}]

a = {a1, a2, a3};
b = {b1, b2, b3};

f[a, b]
b = {b1, b2, b3, b4};
f[a, b]

or do you want to generate a based on the length of x?

f[x_?VectorQ] := Table[Subscript[a, i], {i, 1, Length[x]}].x
f[{x1, x2, x3}]
f[{x1, x2, x3,x4}]

Ulrich

Am 25.01.2012 um 13:08 schrieb Benjamin Hell:

> Hi,
> I'd like to work with vectors of variable length. A short example would
> be this:
> a = {a1,...,an}
> f[x_]:=a.x
> The vector x should be treated as a vector {x1,...,xn} and n should be
> variable and not be specified prior to any calculations.
> One possible calculation would be:
> D[f,x3]
> which should give a3 according to the definition of f above.
>
> How can I implement that in mathematica?
>
> Thanks in advance,
> Benjamin
>
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web