ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CSI2120 Programming Paradigms

2019-03-31 19:47:36  阅读:260  来源: 互联网

标签:function Paradigms string space Programming list CSI2120 characters page



Assignment 3
CSI2120 Programming Paradigms
Winter 2019
Due on April 5th before 11:00 pm in Virtual Campus
6 marks
There are [10 points] in this assignment. The assignment is worth 6% of your final mark.
All code must be submitted in a scm file. Screenshots, files in a format of a word editor, pdfs,
handwritten solutions, etc. will not be marked and receive an automatic 0.
Question 1. [1 point]
Use the built-in function map to replace every number by its reciprocal value in the list. Define a global
1over and use 0 as the reciprocal value for 0, i.e., 0 = 1/0.
(1over '(0 2 3 4 12 0 0 1 0)) '(0 1/2 1/3 1/4 1/12 0 0 1 0))
Question 2. [2 points]
Implement Newton-Rhapson's method for root finding of function in one dimension. Newton-Rhapson
is defined by the iteration ;
where is the current estimate of the root,  is the function evaluated atlobal definition of the function must take three
arguments, the current estimate of the root, the function and the derivative of the function, i.e.,
; (newtonRhap x f fx)
Your routine must stop the iterations if the change in the solution is less than a tolerance. For this
purpose use a global define, i.e.,
(define TOL 1e-6)
See next page for examples.
CSI 2120 page 2
_________________________________________________________________________________________________
Examples:
(newtonRhap 0.1 sin cos) 0
(newtonRhap 2.0 (lambda (x) (- (* x x) x 6))
(lambda (x) (- (* 2 x) 1))) 3.0
(newtonRhap -20.0 (lambda (x) (- (* x x) x 6))
(lambda (x) (- (* 2 x) 1))) -2.000000000000118
Question 3. [3 points]
Implement a routine p_cos which calculates the cosine of an angle in radians. Use the following
product approximation of cosine
Use as many terms until the change with the next term is less than a tolerance. For this purpose use
again the global define,

代写CSI2120作业、代做Programming Paradigms作业
(define TOL 1e-6)
Examples:
(p_cos 0)1
(p_cos (/ pi 2)) 0.0
You are allowed extra global helper functions.

CSI 2120 page 3
_________________________________________________________________________________________________
Question 4. [5 points]
You are not allowed to use any of the built-in string processing function for this question. You can
assume that all lists only contain characters.
a) Write a predicate separator? that returns true if a character is a space, tab or newline and
false otherwise. In Scheme this characters are written #\space, #\tab and #\newline
respectively. The built-in predicate char=? compares two characters for equality.
Example:
(separator #\space) #t
(separator #\b) #f
b) Write a function cpy that copies all characters from an input list into an output list until a
separator is encountered.
(cpy '(#\H #\e #\l #\l #\o #\space #\W #\o #\r #\l #\d)) '(#\H #\e #\l #\l #\o)
c) Write a function drop that removes all characters from an input list until a separator is
encountered and returns the remaining list.
(drop '(#\H #\e #\l #\l #\o #\newline #\W #\o #\r #\l #\d)) '(#\W #\o #\r #\l #\d)
d) Write a predicate same? that compares two list of characters and return true if the characters in
the first input list up to a separator are the same as in the second list.
(same '(#\H #\e #\l #\l #\o #\tab #\W #\o #\r #\l #\d)
'(#\H #\e #\l #\l #\o)) #t
(same '(#\H #\e #\l #\l #\o #\space #\W #\o #\r #\l #\d)
'(#\W #\o #\r #\l #\d)) #f
continued on next page.
CSI 2120 page 4
_________________________________________________________________________________________________
e) Write a function replace that replaces a list of characters in the input list between separators with
another set of characters.
(replace
'(#\a #\space #\b #\i #\r #\d #\space #\e #\a #\t #\s #\space
#\a #\space #\t #\o #\m #\a #\t #\o)
‘(#\a)
‘(#\t #\h #\e)) '(#\t #\h #\e #\space #\b #\i #\r #\d #\space #\e #\a #\t #\s
#\space #\t #\h #\e #\space #\t #\o #\m #\a #\t #\o)
Or more readable:
(list->string (replace (string->list "a bird eats a tomato")
(string->list "a") (string->list "the"))) "the bird eats the tomato"

 

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com 

微信:codinghelp

标签:function,Paradigms,string,space,Programming,list,CSI2120,characters,page
来源: https://www.cnblogs.com/bizhud/p/10632764.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有