数值分析编程代写 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
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 pi so 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!
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:
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).
COMP 424 Final Project Game: Colosseum Survival!
AI算法代写 1.Goal The main goal of the project for this course is to give you a chance to play around with some of the AI algorithms discuss...
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...
CSCI 3022 Final Exam
CS考试代考 Read the following: • RIGHT NOW! Write your name, student ID and section number on the top of your exam. If you’re handwriting your exam,
Read the fol...
Volatility Forecasting Homework
波动率预测代写 1.You will estimate the parameters of a few GARCH-type models using about ten years of data (from Jan 1, 2013 to Nov 30, 2022) for SPY
1.
...