Skip to content

Commit

Permalink
[L5-1] Simplify L2-norm function
Browse files Browse the repository at this point in the history
  • Loading branch information
mesnardo committed Aug 30, 2018
1 parent 531e147 commit ebfbceb
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lessons/05_relax/05_01_2D.Laplace.Equation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,6 @@
" \"\"\"\n",
" Computes and returns the relative L2-norm of the difference\n",
" between a solution p and a reference solution p_ref.\n",
" If L2(p_ref) = 0, the function simply returns\n",
" the L2-norm of the difference.\n",
"\n",
" Parameters\n",
" ----------\n",
Expand All @@ -473,12 +471,10 @@
" Returns\n",
" -------\n",
" diff : float\n",
" The (relative) L2-norm of the difference.\n",
" The relative L2-norm of the difference.\n",
" \"\"\"\n",
" l2_diff = numpy.sqrt(numpy.sum((p - p_ref)**2))\n",
" l2_ref = numpy.sqrt(numpy.sum(p_ref**2))\n",
" if l2_ref > 1e-12:\n",
" return l2_diff / l2_ref\n",
" l2_diff = (numpy.sqrt(numpy.sum((p - p_ref)**2)) /\n",
" numpy.sqrt(numpy.sum(p_ref**2)))\n",
" return l2_diff"
]
},
Expand Down Expand Up @@ -630,7 +626,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Jacobi relaxation: 4473 iterations to reach a relative difference of 9.989253685083211e-09\n"
"Jacobi relaxation: 4473 iterations to reach a relative difference of 9.989253685041417e-09\n"
]
}
],
Expand Down

0 comments on commit ebfbceb

Please sign in to comment.