0
$\begingroup$

Say I have an infinite dimensional vector space $V$ with basis consists of abstract symbols $\{ a_j \}^\infty_{j=0}$, and consider a linear function $f$ on $V$ defined by its action on the basis elements, say $f[a_j]=j *a_{j}+j^2 * a_{j+1}, \forall j\geq 0$. I want to implement this function $f$ in mathematica that computes $f$ for any finite linear combination of $\{a_j\}^\infty_{j=0}$ (i.e. any vector in $V$). Sure I can input $f[a_j]$ into the definition of $f$, but how could I let mathematica know that $f$ is a linear function?

$\endgroup$

1 Answer 1

2
$\begingroup$

Linearity is defined as f[x_+y_]= f[x]+f[y] and f[lam x_] = lam f[x], where lam is a scalar. Further, do not use subscripted variables, use indexed ones instead. Therefore:

Clear["Global`*"];
f[a[j_]] := j  a[j] + j^2 a[j + 1];
f[x_ + y_] := f[x] + f[y];
f[lam_?NumericQ  x_] := lam f[x]

We can now calculate e.g. the image of some vector a[0] + a[1] + 2 a[2]:

f[a[0] + a[1] + 2 a1[2]]
%% // Simplify

a[1] + a[2] + 2 (2 a[2] + 4 a[3])

a[1] + 5 a[2] + 8 a[3]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.