In: Computer Science
Using Matlab create an m. file that solves the following problem. Ramanujan's taxi. S. Ramanujan was an Indian mathematician who became famous for his intuition for numbers. When the English mathematician G. H. Hardy came to visit him in the hospital one day, Hardy remarked that the number of his taxi was 1729, a rather dull number. To which Ramanujan replied, "No, Hardy! No, Hardy! It is a very interesting number. It is the smallest number expressible as the sum of two cubes in two different ways." Verify this claim by writing a program that takes an integer command-line argument n and prints all integers less than or equal to n that can be expressed as the sum of two cubes in two different ways - find distinct positive integers a ,b ,c , and d such that a3 + b3 = c3 + d3. Use four nests for loops. Now, the license plate 87539319 seems like a rather dull number. Determine why it's not.
Please find the required MATLAB script as the following:
%=======================================================================
clear all;clc;
n = input('Input number ''n'': '); % Taking input value for n
for i=1:n % For number till n
temp_list = []; % Creating temporary list to store cube paris
for j=1:ceil(i^(1/3)) % As j^3 can not exceed i, iterate j till
i^(1/3)
k_difr = (i-j^3); % From relation j^3+k^3 =
i
for k=1:ceil(i^(1/3)) % As k^3 can not exceed i, iterate k till
i^(1/3)
if(k^3==k_difr) % Checking if such k
exists
temp_list =
[temp_list;sort([j,k])]; % Store pairs in sorted
temp_list =
unique(temp_list,'rows'); % Select such unique pairs
break;
end
end
end
if(size(temp_list,1)>=2) % Printing numbers with atleast 2
feasible pairs
fprintf('n=%d, (a=%d,b=%d),
(c=%d,d=%d)\n',i,temp_list(1,1),temp_list(1,2),temp_list(2,1),temp_list(2,2));
end
end
%=======================================================================
Sample output for n = 200000
==================================================================================
==================================================================================
The number 87539319 is the first number that can be represented by three pairs of number for which the sum of cubes of each number in a pair equals number 87539319 . These pairs are
87539319 = 1673 + 4363 = 2283 + 4233 = 2553 + 4143
In case of any clarificaiton, please comment!