Skip to content

Commit

Permalink
Merge pull request #147 from tkoolen/symbolic-simplify
Browse files Browse the repository at this point in the history
Simplify using map!
  • Loading branch information
tkoolen authored Jan 31, 2017
2 parents f2bf264 + 4ac60c7 commit fe47724
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions examples/Symbolic double pendulum.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {
"collapsed": false
},
Expand All @@ -34,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -65,7 +65,7 @@
"[ g ]"
]
},
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -88,7 +88,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {
"collapsed": false
},
Expand All @@ -101,7 +101,7 @@
" Vertex: lower_link, Edge: elbow"
]
},
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -138,7 +138,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {
"collapsed": false
},
Expand All @@ -149,7 +149,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {
"collapsed": false
},
Expand All @@ -166,7 +166,7 @@
"[q_2]"
]
},
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -178,7 +178,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {
"collapsed": false
},
Expand All @@ -195,7 +195,7 @@
"[v_2]"
]
},
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -214,7 +214,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {
"collapsed": false
},
Expand All @@ -232,27 +232,21 @@
"[ I_2 + c_2*l_1*cos(q_2) I_2 ]"
]
},
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Mass matrix\n",
"M = mass_matrix(x)\n",
"function simplify!(a::Array{SymPy.Sym})\n",
" for i in eachindex(a)\n",
" a[i] = simplify(a[i])\n",
" end\n",
" a\n",
"end\n",
"simplify!(M.data) # Note: M is a Symmetric matrix type; need to simplify the underlying data\n",
"map!(simplify, M.data) # Note: M is a Symmetric matrix type; need to simplify the underlying data\n",
"full(M) # convert to full form so that it is pretty-printed (minor bug in SymPy.jl)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {
"collapsed": false
},
Expand All @@ -274,7 +268,7 @@
" 2 "
]
},
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -286,7 +280,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {
"collapsed": false
},
Expand All @@ -300,7 +294,7 @@
"-g*(c_1*cos(q_1) + c_2*cos(q_1 + q_2) + l_1*m_2*cos(q_1))"
]
},
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand Down

0 comments on commit fe47724

Please sign in to comment.