I want to realize the following idea in Mathematica.
I've got a matrix
{{a,b},{c,d}}
which is multiplied to a vector {h,k}
leading to
{{a h + b k}, {c h + d k}}.
Imagine now that a
is an operator and I want to apply it to h
, instead of multiplying. Primitive substitution {a h -> a@h}
helps, but it is not quite a good approach while it's not working in more sophisticated cases.
Thank you!
EDIT1: The problem is solved partially, all comments are very useful. But still I am a little bit stacked, so I'm posting the update trying to explain my exact problem.
The problem is following. I want to construct the matrix
{{a[x], b},{c, d}}
where a[x]
is an operator (function) and b,c
and d
are arbitrary expressions (which are symbolic in general). After applying the operation
{{a[x], b},{c, d}}.{{h}, {k}}
I want to obtain
{{a[h] + b k}, {c h + d k}}
I want this operation to work not only for numbers and functions as it was proposed in answers below but with arbitrary symbolic expressions. I mean I want Mathematica to understand that if x
and p
are not functions but just variables, then x*p
means multiplication, otherwise it means x[p]
.
Moreover I want this operation to work in more general cases, e.g.
{{a[x], b},{c, d}}.M.Transpose[{{a[x], b},{c, d}}],
where M
is an arbitrary matrix.
I would be very grateful for any ideas.
Answer
Picking up on Marius tip on Inner in the comments:
Inner[Apply[#1, {#2}] &, {{a, b}, {c, d}}, {h, k}]
And @ciao offered a better version in comments:
Inner[#1[#2] &, {{a, b}, {c, d}}, {h, k}]
Comments
Post a Comment