Enter the plants listed at the end of this question into a Prolog database of ga
ID: 3787386 • Letter: E
Question
Enter the plants listed at the end of this question into a Prolog database of garden plants. You will have to design the database and decide on the name for constants and predicates.
a) Add a rule which finds hardy plants (zone less than 6) that can grow at least to a height of 48in and are perennials.
?- hardy(P).
b) Add a rule trio/6 to your database that will allow you to get three different plants with the requested colors.
?- trio(red,X,white,Y,blue,Z).
c) Extend your database to suggest plants for Paul and Mary. Note that Mary does not like yellow and Paul likes plants that may grow to 36in. Paul and Mary live in zone 7.
?- suggestion(paul(X),mary(Y)).
Garden plants:
Blue Lobelia, partial sun, shade, sun, blue, 6-12in., zones 2- 11, annual
Impatiens, shade, 12-36in., red, white, pink, zones 10-11, annual
Periwinkle, partial sun, shade, sun, blue, 0-6in., zones 4-9, perennial
Anemone, partial sun, sun, pink, white, 12-36in., zones 4-8, perennial
Marigold, sun, yellow, orange, 3-12in., annual
Black-eyed susan, partial sun, sun, yellow, 12-24in., zones 3- 11, annual
Bleeding heart, partial sun, shade, pink, white, 6-12in., zones 3-9, perennial
Chrysanthemum, partial sun, sun, red, yellow, blue, white, 12- 36in., zones: 5-9, perennial
False Lupine, partial sun, sun, yellow, 12-96in., zones: 4-8, perennial
Heather, partial sun, sun, purple, 36-96in., zones 6-10, perennial
Iris, partial sun, sun, blue, orange, pink, red, white, 6-36in, zones: 3-9, perennial
Phlox, purple, red, pink, 12-36in., zones 2-11, annual
Explanation / Answer
The theorems regarding Newton's technique sometimes embark with the concept that the initial guess is ``close enough'' to the solution. Since you are doing not acknowledge the solution once you start, but do you acknowledge once it's ``close enough?'' In one-dimensional problems, the answer is essentially that if you retain one's eyes removed from places where the by-product is zero, then any initial guess is OK. Plenty of to the aim, if you acknowledge that the solution lies in some interval and $ f'(x) e0$ on that interval, then the Newton iteration will converge to the solution, starting from any purpose inside the interval. Once there unit zeros of the by-product close to , Newton's technique can show extraordinarily erratic behavior and can or may not converge. Inside the last a region of the previous exercise, you saw a case where there unit several roots, with zeros of the by-product between them, and moving the initial guess to the right emotional the chosen root to the left.
Exercise 6: throughout this and additionally the subsequent exercise, you will have associate interest inside the sequence of iterates, not merely the final word result. Re-enable the disp statement displaying the values of the iterates in newton.m.
Write a perform m-file for the cosmx perform used within the previous science lab ( $ f(x)=cos x - x$). Confirm to calculate the every perform and its by-product, as we've an inclination to did for f1, f2, f3 and f4.
Use Newton to look out the premise of cosmx starting from the initial worth x=0.5. what is the answer and also the method many iterations did it take? (If it took over ten iterations, come and confirm your formula for the by-product is correct.)
Again, use Newton to look out the premise of cosmx, but begin from the initial worth x=12. Note that $ 3pi<12<4pi$, so there unit several zeros of the by-product between the initial guess and additionally the basis. you have to be compelled to observe that it takes the utmost style of iterations and seems to not converge.
Try identical initial worth x=12, but to boot use maxIts=5000. (To do that, embody 5000 inside the call: Newton('cosmx',12,5000)) (This goes to cause associate oversized style of lines of written knowledge, but you are planning to verify variety of these lines.) can it realize a solution in fewer than 5000 iterations? what proportion iterations can it take? can it get identical root as before?
Look at the sequence of values of x that Newton's technique chosen once starting from x=12. there isn't any real pattern to the numbers, and it's pure probability that finally place the iteration near the premise. Once it's ``near enough,'' in any case, it finds the premise quickly as you will see from the derived errors. is that the ultimate derived error smaller than the sq. of the proper away preceding derived error?
You have merely discovered a typical behavior: that the iterations seem to leap regarding with none real pattern until, on the face of it unknowingly, Associate in Nursing retell lands inside the circle of convergence which they converge quickly. This has been delineate as ``wandering around looking for a good initial guess.'' it's even plenty of putting in place third-dimensional problems where the likelihood of eventually landing inside the ball of convergence is very small.
Another accomplishable behavior is easy divergence to time. the following exercise presents a case of divergence to time.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.