R代写:Statistics 4960/6260 一个长度不限整数乘法的实现


Email me one file. Do not use a “reply” to email your file. Use .R as the extension. The file name submitted by a student named Albert Einstein is AlbertEinsteinAssign3.R I should be able to load your code into the R environment by using the “Open Script” feature of R. Then I should be able to run your code. Put your name as the first line of your .R file. This will be a line that is executable, and look this: name = “Albert Einstein”. Of course your own name will be substituted for Albert Einstein. When I run tests on your code, I will want to know whose code is running. Your code should be well-commented, and indented so a reader can easily follow the code. Bring a print out of your file to class.

_The prototype of the file is: _long.mult<- function(x,y)

_x and y are numeric vectors. Each element of these vectors has an integer value in the range 0 to _999.Each of these vectors stores one number. The first element of x and y contain the most significant digits.

_If n = length(x), then the number stored in x is sum(x*p), where p =1000^((n-1):0) _Examples:

To store 123456789 into x we use the R command x = c(123,456,789)

To store 45000892012 into y we use the R command y = c(45,0,892,012)

_Note that when you store a very large number into x it cannot be represented in the double precision or _integer format used by R. Note that x and y are both non-negative integers.

_The function will return the product of x and y. The product will be stored in the same format as the input _arguments. Check the input arguments for validity.

_If you should happen to find an R function in some package that performs multiplication on very long _numbers, you MAY NOT use it. If you do, your grade will be non-positive.

_Use the function names and arguments indicated. DO NOT have any tests in your file. The only _executable statement is the name = statement. Note that it is not Name =. Also make sure it is not a comment. Make sure your file does not produce a syntax error. Your file should contain only the name = statement, function header comments, and your function.

Given below is an example of using the function.

> x = c(123,456,789)

> y = c(987,654,321)

> z = long.mult(x,y)

> z

[1] 121 932 631 112 635 269

Given below is another example.

> x = c(3,400,999,65,270)

> y = c(478,231,598)

> z = long.mult(x,y)

> z

[1] 1 626 465 217 780 578 401 460
kamisama wechat