Question: Regarding C programming, more specific threads: use Newton's method to practice programming with the C 1 1 thread library. Give a function f , say
Regarding C programming, more specific threads:
use Newton's method to practice programming with the C thread library. Give a function f say fx x where x denotes the third power of x Newton's method iteratively strives to find a root of f Starting with a value x one sets xk xk fxk fxk Convergence of this is unclear, and even if it does converge, it is unclear what root of f is approached.
sing the C thread library a program called newton that computes similar pictures for a given functions fx xd for complex numbers with real and imaginary part between and The program should write the results as PPM files see the description of PPM below to the current working directory. The files should be named newtonattractorsxdppm and newtonconvergencexdppm where d is replaced by the exponent of x that is used.
Your program should accept command line arguments
newton tlnewton lt
The last argument is d the exponent of x in xd The argument to l gives the number of rows and columns for the output picture. The argument to t gives the number of threads used to compute the pictures. For example, the above command computes images of size x for the polynomial x It uses threads for the Newton iteration.
Implement details: Iteration
If xi is closer than to one of the roots of fx then abort the iteration.
Newton iteration does not converge for all points. To accommodate this, abort iteration if xi is closer than to the origin, if the absolute value of its real or imaginary part is bigger than or if the iteration takes steps ore more. In the pictures treat these cases as if there was an additional zero of fx to which these iterations converge.
You have to run the iteration for each point until either of these criteria is met. In particular, the cut off for the number of iterations mentioned later may only be applied after completing the iteration. Implementation details: Simplifications
You may assume that the degree is small, ie less than and hardcode optimal formulas case by case.
You may assume that the number of lines is not too large, ie less than It is advantageous to implement the writing step prior to the computation step, since you will have accessible feedback once the writing is in place. To guarantee meaningful input values in the writing thread add the following initialization to your computing threads:
for sizet cx ; cx nmblines; cx attractorcx; convergencecx;
Make sure that the attractor and convergence value indeed is assigned meaning in your encoding. Computation
It remains to implement the computation in order to complete the program. Since you can use functionality from complex.h and you can hardcode your formula, this step is largely about finding an expression for the iteration step that is as efficient as possible. Recall that using cpow is not an option.
Inserting the Newton iteration step naively, you obtain x xd dxd How can you simplify it
When hardcoding the expression that you derive from this, the following syntax is convenient:
switch degree case : STATEMENTS FOR DEGREE ; break; case : STATEMENTS FOR DEGREE ; break; case : STATEMENTS FOR DEGREE ; break; insert further cases default: fprintfstderr "unexpected degree
; exit;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
