课程主页:https://graphics.stanford.edu/courses/cs205a-13-fall/schedule.html

这次回顾作业8。

Problem 1

(a)代码如下:

M = zeros(nParticles);
[m, n] = size(edges);
for i = 1: m
    x = edges(i, 1);
    y = edges(i, 2);
    M(x, x) = M(x, x) - 1;
    M(x, y) = M(x, y) + 1;
    M(y, x) = M(y, x) + 1;
    M(y, y) = M(y, y) - 1;
end

(b)令

那么方程为

所以代码如下:

[m, n] = size(secondOrderMatrix);
matrix = zeros(2 * m);
matrix(1: m, m+1: 2*m) = eye(m);
matrix(m+1: 2*m, 1: m) = secondOrderMatrix;

(c)

(i)前向欧拉

代码如下

x = x + dt * firstOrder * x;

(ii)后向欧拉

代码如下

x = inv(eye(2 * n) - dt * firstOrder) * x;

(iii)梯形法

代码如下

x = inv(eye(2 * n) - dt * firstOrder / 2) * (eye(2 * n) + dt * firstOrder / 2) * x;

(d)leapfrog

代码如下

positions = positions + dt * velocities;
velocities = velocities + dt * force * positions;

Problem 2

(a)求导可得

所以$E(t)$关于$t$是常数。

(b)

因为

以及

所以

(c)因为

所以

(d)