CS 111. Homework 2

CS 111. Homework 2
Submit your codes and answers as a jupyter notebook.
If you worked with a partner, you must each turn in your own homework paper, and report the name and perm number of your partner. No groups of more than two allowed.
1. According to Wikipedia, “the Poisson-Boltzmann equation is a useful equation in many settings, whether it be to understand physiological interfaces, polymer science, electron interactions in a semiconductor, or more. It aims to describe the distribution of the electric potential in solution in the direction normal to a charged surface. This distribution is important to determine how the electrostatic interactions will affect the molecules in solution”. In the case where the solution is mildly concentrated, one can consider the linearized Poisson-Boltzmann equation:
−∆u+ku = S, (1) where u is the unknown that we seek to compute (here, the electrochemical potential), S is a source term, and
k is a given positive constant.
To approximate this equation in a rectangular domain [a,b]×[c,d], we consider a grid with mX grid points
in the x-direction and mY grid points in the y-direction, and use the following formula: ui+1,j −2ui,j +ui−1,j ui,j+1 −2ui,j +ui,j−1 
− ∆x2 + ∆y2 +kui,j =Si,j, (2) where ∆x and ∆y are the distances between adjacent grid points in the x and y directions, respectively. On the
boundary of the domain, we impose that u is given.
1.1. ExplaininyourreporthowyoucreatethelinearsystemAu=rhsfromequation(2),whereAisamatrix,
u is the solution vector, and rhs is a right-hand side vector.
1.2. Implement in Python the numerical method.
1.3. For k = 1, report the error in the maximum norm1 between your numerical solution and the exact solution u(x, y) = cos(x) + sin(y) as the grid is refined, i.e., fill out the following table below2 . In this question, take the boundary condition on all sides of the domain to be given by the exact solution. The domain is [0, 1] × [0, 1].
Resolution (mX × mY ) 50×50
1.4. Produce a figure of the solution when k = 1, S = 0 and u on the boundary is 0, except on the top where it is 1. You should take 100 grid points in each spatial directions.
1Recall that the error in the maximum norm is the largest error on the grid in absolute value. 2Note that you need to find the corresponding S(x,y) analytically.
程序代写 CS代考 加QQ: 749389476