Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8184
| From | Ulrich Arndt <ulrich.arndt@data2knowledge.de> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: calculating with vectors of variable length |
| Date | 2012-01-26 08:31 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jfr315$nin$1@smc.vnet.net> (permalink) |
| References | <201201251208.HAA06160@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
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: calculating with vectors of variable length Ulrich Arndt <ulrich.arndt@data2knowledge.de> - 2012-01-26 08:31 +0000
csiph-web