3
$\begingroup$

I want to define pure functions x(#1,#2) and y(#1,#2) like enter image description here But they aren't proper pure functions in the current form. How to modify the code?

$\endgroup$
2
  • 1
    $\begingroup$ You are missing an ampersand &. Example. $\endgroup$
    – Domen
    Commented Mar 12, 2023 at 10:28
  • $\begingroup$ thanks! In your example, how can one define x(#1,#2) and y(#1,#2) separately rather than x and y as a vector together? $\endgroup$
    – feynman
    Commented Mar 12, 2023 at 10:48

1 Answer 1

4
$\begingroup$

You have to reapply Function separately for x and y, for example:

{x, y} = Function @@@ (({{Cos[a], Sin[a]},{-Sin[a], Cos[a]}}) . ({{#1},{#2}}))

Example 1

If you want to have a "column vector" like notation on the left side, you have to properly match the levels, for example:

{{x}, {y}} = List@*Function @@@ ({{Cos[a], Sin[a]}, {-Sin[a], Cos[a]}} . {{#1}, {#2}});

{{x}, {y}} = Map[Function, {{Cos[a], Sin[a]}, {-Sin[a], Cos[a]}} . {{#1}, {#2}}, {2}];

Example 2

$\endgroup$
1
  • $\begingroup$ many thanks! I'm curious why for column vectors it's so much more work, as simply mimicking the row vector approach will yield an error saying: Lists {X} and Cos[a] #1+Sin[a] #2& are not the same shape. $\endgroup$
    – feynman
    Commented Mar 12, 2023 at 11:16

Your Answer

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

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