Search the whole station

# 数值分析编程代写 Programming代写 Python代写 编程代写

496

## Programming assignment #1: rootfinding

### Problem 1. Write a Python function:

`roots = findroots(p, a, b)`

whose arguments are:

• p: a list or ndarray of double-precision floating point numbers of length n+ 1 defining a degree n polynomial such that p[i] contains the value of pso that p defines the polynomial p(x) = p0 + p1x + p2x2 + · · pnxn,
• a, b: two finite double-precision floating point numbers defining an interval [a, b],

and which computes all real roots of p(x) on the interval [a, b]. The function should return a list of the real roots in increasing order : if p has k roots xisuch that a x1 x2 ≤ · · · ≤ xk b, then roots[i] (1 <= i <= k) gives the value of xi. If there are no roots, then f returns an empty list (i.e. len(roots) == 0).

To implement this function, one idea is to use Sturm’s theorem recursively combined with a 1D rootfinder (see this page for more details about how to apply Sturm’s theorem—we will also discuss it in class). For this problem, you are free to use the scipy function brentq.

Test your function as you develop it—namely, use polyroots to check the whether the roots you compute are correct!

### Problem 2.数值分析编程代写

An algebraic surface (click through to see pictures of many examples) is defined as the locus of points which satisfies:

p(x, y, z) = 0, (x, y, z) R3, (1)

where p is a multivariable polynomial. Goursat’s surface is a quartic algebraic surface defined by (1) where:

p(x, y, z) = x4 + y4 + z4 + a(x2 + y2 + z2)2 + b(x2 + y2 + z2 ) + c = 0, (2)

for some choice of the parameters a, b, c R.

Using findroots, we will use raytracing to render an image of Goursat’s surface. We pick a point r0 = (x0, y0, z0), a unit ray direction d = (dx, dy, dz), and define the ray:

r(t) = r0 + td = (x0 + tdx, y0 + tdy, z0 + tdz), t ≥ 0. (3)

We then find the values of t for which (1) holds:

p(r(t)) = 0, t ≥ 0. (4)

Note that the composition of a multivariate polynomial with a single variable polynomial is just a single variable polynomial. This means that we can use findroots to solve (4).

#### Our goal is to trace rays from an “orthographic camera”. 数值分析编程代写

In our simplified raytracing, we will set up a grid of rays, one for each pixel in an image, solve (4) using findroots to find the first intersection along the ray, and color each pixel using a simple Lambertian model of reflectance:

• We will represent colors as 3-tuples of floating-point values, (r, g, b), where r, g, b [0, 1] are the red, green, and blue values in the RGB color model.
• If we let C be the color of our surface, we will additionally shade it based on the angle that the ray makes with the surface. If n(x, y, z) is a unit surface normal, then for each ray which intersects the surface, we let cos(αij ) = n d, and set the corresponding pixel value to:

Cij= cos(αij)C. (5)

We will represent the image as an m × n × 3 ndarray, where img[i, j, :] gives the RGB values for the (i, j)th pixel. So, we use the same direction vector d for each pixel, but must vary the initial ray position so that we get a different parallel ray for each pixel. See this image. After creating the image, use plt.imsave to save it to disk.

Note that to use findroots to solve (4), we need to write p(r(t)) as a polynomial in t. This is tricky to do automatically using numpy, but you are welcome to try. Two other options: use sympy, or write down the polynomial by hand and then implement it as a new Python function (e.g., p of r(t, r, d, a, b, c)—note the dependence on the parameters).

The prev: The next:

### Related recommendations

• #### 国外python代考-学计算机的留学生一定要了解什么是python代考

702

学计算机的留学生一定要了解什么是python代考 国外python代考 计算机在现在是一个非常热门的行业，但是计算机专业也是非常难学的，计算机专业和法学、医学齐名，这三个专业被称之为最难熬的三个专业。这...

View details
• #### programming程序代写-完不成程序作业该怎么办？可以找

464

完不成程序作业该怎么办？可以找programming代写老师帮忙吗？ programming程序代写 相信很多在国外留学的同学，对国外的专业考试和作业有着莫名的紧张感和无力感，因为对当地文化不是很了解。和老师同学沟通...

View details
• #### python代写哪里找的价位便宜?代写Python的通过率高不高？

933

python代写哪里找的价位便宜?代写Python的通过率高不高？ python代写 随着人们生活水平的提高，人们的精神追求也在逐步的提高。对于出国留学都有了新的认识有了很高的思想觉悟，不再有人认为出国留学就是有钱...

View details
• #### 数据科学代写 data1x02代写 Python代写 数据作业代写

664

data1x02 Project 数据科学代写 Submission 1: Report Submit a written report on your work, as a PDF document. • This should be submitted through the link in the Canvas site. Submission 1: Repo...

View details
1