PSBC Project 1 Due Tuesday, March 7th 2017 Question 1: Approximate the EulerMascheroni constant Despite its appearance in many seemingly unrelated fields and applications, the EulerMascheroni constant γ ≈ 0.577215664901533 remains a mystery and is not as well-known as other mathematical constants like π. Basic questions like whether it is irrational or not are still open. In many situations, it is more convenient to approximate complicated constants like this by the quotient of integers. Find the best such approximations p/q such that |p/q − γ| is smallest among all possible positive integers p and q such that p + q is smaller than or equal to a given positive integer. Task: Write a function AppEM such that [p,q] = AppEM(N) returns the best pair of integers p and q, such that p+q is less than or equal to N. Record your result for N = 2017. Note: you can just copy the above value of the constant with fifteen decimal points, otherwise you have to call the symbolic constant and convert it into double precision: em const = double(eulergamma). The first few lines of your code look like: 1 2 3 function [p , q ] = AppEm ( N ) % APPEM Approximate the Euler - Mascheroni constant by the rational % number p /q , among all pairs of (p , q ) such that p +q <= N 4 5 em_const = 0 .577215664901533 ; Hint: you have to compare candidate pairs (p, q), and save it (think about how you find the maximum component of a vector?). Question 2: Lucky number An integer n is said to be lucky, if it has distinct, odd prime factors (thus at least two factors), and for any of its prime factor p, p − 1 divides n − 1. For example, Any prime number is not lucky, because it has only one prime factor (itself) The number 6 = 2 × 3 is not lucky, because there is an even factor 2 The number 45 = 3 × 3 × 5 is not lucky, because the prime factor 3 appears twice (not distinct) The number 15 = 3 × 5 is not lucky, because 4(= 5 − 1) does not divide 14(= 15 − 1) 1 The number 10585 = 5 × 29 × 73 is lucky, because all the prime factors (5, 29 and 73) are odd and distinct, and 10584 10585 − 1 = = 2646, 4 5−1 10584 10585 − 1 = = 378, 28 29 − 1 10584 10585 − 1 = = 147. 72 73 − 1 Write a function luckynum such that luckynum(N) returns the smallest lucky number greater than or equal to N. Record your output for N = 2017. 1 2 function n = luckynum ( N ) % LUCKYNUM Find the smallest lucky number that is greater than or equal to N Hint: for a given number, check whether it passes all the conditions to be lucky. Question 3: Perfect numbers An integer n is said to be perfect, if its square consists all nine non-zero digits. Examples include 11826 and 30384, since 118262 = 139854276, 303842 = 923187456. Find the perfect number n, such that n2 is closest to 360322017. Hint: better to convert the number into a vector of individual digits or string of characters/digits (using num2str). Some useful commands Depending on your approach, you may use some of the following commands: factor (find the prime factors of a number), strcmp, strcat, .. (various functions for string characters), union, intersect, setdiff, setxor, ismemeber, unique (set operation on vector of numbers or string characters). Ask the lecturer or the lab demonstrators, if you are not sure whether there is a specific built-in function for your desired operation. It is common that the same approach can be implemented in different ways and different people may give different answers for the same question (though all work)—think critically. Other information: You can assume that the argument is always a positive integer, and no need to validate the input. You should restate the problem, so that the reader can understand your report without this project description. The report should indicate to the reader how well you understand the problem and the approach you take. Your goal will be to communicate your solutions to another person rather than to show you’ve completed the assignment. List the code for the whole function at the end of each question, or in an appendix. Make your source code more readable, by keeping the indentation and stylistic features. Your result should be reproduced from the code attached. Keep your page length not exceeding eight A4 pages. 2
© Copyright 2026 Paperzz