Using matrix-form matrices and vectors in function definitions;
- To: mathgroup at smc.vnet.net
- Subject: [mg107248] Using matrix-form matrices and vectors in function definitions;
- From: Chris <c56young at gmail.com>
- Date: Sat, 6 Feb 2010 03:26:59 -0500 (EST)
I'd like to be able to use matrix-form matrices and vectors in my
definitions for geometric shapes such as M=F6bius strips. But I run into
problems with Mathematica adding extra nesting, and have to apply Flatten to
get the products back into correct form. Isn't there an easier way to
do this? I'm using Mathematica 5.
I defined rotation matrices as
\!\(\*
RowBox[{\(RotZ[t_]\), ":=",
RowBox[{"(", GridBox[{
{\(Cos[t]\), \(-Sin[t]\), "0"},
{\(Sin[t]\), \(Cos[t]\), "0"},
{"0", "0", "1"}
}], ")"}]}]\)
and
\!\(\*
RowBox[{\(RotY[t_]\), ":=",
RowBox[{"(", GridBox[{
{\(Cos[t]\), "0", \(-Sin[t]\)},
{"0", "1", "0"},
{\(Sin[t]\), "0", \(Cos[t]\)}
}], ")"}]}]\)
Then I simply wanted to use them in a function for a M=F6bius strip:
\!\(\*
RowBox[{\(moebiusstrip6[u_, v_]\), ":=",
RowBox[{
RowBox[{\(RotZ[u]\), ".",
RowBox[{"(", GridBox[{
{"1"},
{"0"},
{"0"}
}], ")"}]}], "+",
RowBox[{\(RotZ[u]\), ".", \(RotY[u]\), ".",
RowBox[{"(", GridBox[{
{"v"},
{"0"},
{"0"}
}], ")"}]}]}]}]\)
But I got error messages:
In[148]:=
ParametricPlot3D[moebiusstrip6[u,
v]//Evaluate,{u,0,2Pi},{v,-0.3,0.3},PlotPoints\[Rule]{40,5},Axes\
[Rule]
True,Boxed\[Rule]True];
>From In[148]:=
\!\(\*
RowBox[{\(ParametricPlot3D::"
ppfun"\), \(\(:\)\(\ \)\), "\<\"Argument \\!\\({\\(\\(Cos[
u]\\)\\) + \\(\\(v\\\\ \\(Cos[
u]\\)\\^2\\)\\)}\\) is not a list with three or four elements. \
\\!\\(\\*ButtonBox[\\\"More=85\\\", ButtonStyle->\\\"RefGuideLinkText\\
\", \
ButtonFrame->None, ButtonData:>\\\"ParametricPlot3D::ppfun\\\"]\\)
\"\>"}]\)
>From In[148]:=
\!\(\*
RowBox[{\(ParametricPlot3D::"
ppfun"\), \(\(:\)\(\ \)\), "\<\"Argument \\!\\({\\(\\(Sin[
u]\\)\\) + \\(\\(v\\\\ \\(\\(Cos[
u]\\)\\)\\\\ \\(\\(Sin[u]\\)\\)\\)\\)}\\) is not a list with three
or \
four elements. \\!\\(\\*ButtonBox[\\\"More=85\\\", \
ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, \
ButtonData:>\\\"ParametricPlot3D::ppfun\\\"]\\)\"\>"}]\)
>From In[148]:=
\!\(\*
RowBox[{\(ParametricPlot3D::"
ppfun"\), \(\(:\)\(\ \)\), "\<\"Argument \\!\\({v\\\\ \\(\\(Sin[
u]\\)\\)}\\) is not a list
with three or four elements. \\!\\(\\*ButtonBox[\\\"More=85\\\", \
ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, \
ButtonData:>\\\"ParametricPlot3D::ppfun\\\"]\\)\"\>"}]\)
>From In[148]:=
\!\(\*
RowBox[{\(General::"stop"\), \(\(:\)\(\ \)\), "\<\"Further output
of \\!\\(ParametricPlot3D :: \\\"ppfun\\\"\\) will be suppressed
during \
this calculation. \\!\\(\\*ButtonBox[\\\"More=85\\\", \
ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, \
ButtonData:>\\\"General::stop\\\"]\\)\"\>"}]\)
I had to apply Flatten to each matrix-and-vector dot-product to make
it work:
\!\(\*
RowBox[{\(moebiusstrip5[u_, v_]\), ":=",
RowBox[{
RowBox[{"Flatten", "[",
RowBox[{\(RotZ[u]\), ".",
RowBox[{"(", GridBox[{
{"1"},
{"0"},
{"0"}
}], ")"}]}], "]"}], "+",
RowBox[{"Flatten", "[",
RowBox[{\(RotZ[u]\), ".", \(RotY[u]\), ".",
RowBox[{"(", GridBox[{
{"v"},
{"0"},
{"0"}
}], ")"}]}], "]"}]}]}]\)