I think we should make all of the assertion tests hidden, except maybe one
for each problem that shows what the input/output format should be.
Ideally each question stands on its own, so correct prior questions aren't
needed to succeed at the new question. Or at least keep the build up on prior
answers at a minimum.
Use of templates and initialization code should be used so that the student
is focusing on learning the new content for that particular lesson (e.g. if
they are forming final EoMs, then give them the kinematics and forces).
The homeworks should be developed in a private github repository.
To check whether symbolic equations are correct, it's best to evaluate them
with some specific or random numerical inputs. The basic form of the asserions
should look like:
This will check floating point evaluations of the symbolic expressions. Do it
for several unique sets of numerical inputs to check the a realistic range of
values. This will avoid the long duration required to simplify symbolics and
avoid the problem that comparing two symbolic expressions directly will
generally fail.
Symbolic calculations can often take a long time to compute especially for
naive choices in how the code is written. We'll probably need a way to have
nbgrader time out on the autograding and give up. We should warn students that
correct solutions should take only a second or so to run (and design our
problems so that is true).
Problem example: have them create two nonlinear symbolic expressions with
functions of time, differentiate with respect to time, this results in
equations linear in the df/dt terms, then solve the system of equations
for the df/dt terms.
A problem where they try evaluating a matrix of non-trivial expressions using evalf, lambdify, xreplace so they can learn the differences.
Pick some reasonalby difficult linear algegra problem that lets them explore some other things, like determinants or even eigenvalues (of small matrices). Have them solve the linear algebra problem with sympy
A problem that introduces the solve() function where they have to solve a non-linear trigometric function (for example the constraint equation from a 4 bar linkage is solvable example), let them see the multiple solutions and how to extract them from sympy's output.
You could give them a very long complicated symbolic expression (like 1000s of operations) and then have them lambify it and evaluate it. Have them time the execution with timeit. Then have them cse the expression to see how it simplifies and then introduce the cse=Trye flag for lambdify which does cse internally. Have them evalute and time the new function. There should be a reduction in execution speed. They could use count_ops to show the operation count for the original expression and the set of cse expressions. Note that cse=True is new in sympy 1.9.
Part 3 (40 points): Reference Frames, Orientation, Direction Cosine Matrices, Euler Angles
Pick some problems from Kane's two books as inspiration.
SD: 1.1, but change the numbers and the vector lambda
Make a multibox problem like this https://docs.sympy.org/latest/_images/kin_angvel2.svg The idea is to stack some boxes, attach triads to each box, and then rotate the boxes one-by-one about the x, y, or z axes for successive simple rotations, the rotation matrix from the first to last box should be computed. The question should be designed such that they do the matrix forumlations manually (not using ReferenceFrame.orient_axis(). Or ask them to do both ways and show their manual formulation is the same as what successive ReferenceFrame.ortient_axis() would do. If you want to sketch a "cans" drawing of this too, that could help connect to Heike's class (if she shows the cans).
SD: 1.8 (redraw the figure so we don't violate copyright and then change the numbers and the vector)
Homework design
Homework inspiration sources
Tips
To check whether symbolic equations are correct, it's best to evaluate them with some specific or random numerical inputs. The basic form of the asserions should look like:
This will check floating point evaluations of the symbolic expressions. Do it for several unique sets of numerical inputs to check the a realistic range of values. This will avoid the long duration required to simplify symbolics and avoid the problem that comparing two symbolic expressions directly will generally fail.
Symbolic calculations can often take a long time to compute especially for naive choices in how the code is written. We'll probably need a way to have nbgrader time out on the autograding and give up. We should warn students that correct solutions should take only a second or so to run (and design our problems so that is true).
Homework suggestions
solve()
function where they have to solve a non-linear trigometric function (for example the constraint equation from a 4 bar linkage is solvable example), let them see the multiple solutions and how to extract them from sympy's output.timeit
. Then have them cse the expression to see how it simplifies and then introduce thecse=Trye
flag for lambdify which does cse internally. Have them evalute and time the new function. There should be a reduction in execution speed. They could usecount_ops
to show the operation count for the original expression and the set of cse expressions. Note thatcse=True
is new in sympy 1.9.