Skip to main content
2 of 5
added 908 characters in body
flawr
  • 43.9k
  • 7
  • 104
  • 249

#Matlab Note that a = n^2 iff log(a) = log(n)*2 iff log(log(a)) = log(log(n))+log(2). So this function is just finding the zero of the function f(a) = log(log(n))+log(2) - log(log(a)) which obviously is at a = n^2.

function s = g(n)
    f = @(a) log(log(n))+log(2)-log(log(a));
    s = fnzeros(f);
end

Here some other not very creative functions:

This function creates a n x n matrix of random numbers (between 0 and 1) and then returns the number of elements.

g=@(n)numel(rand(n));

The following functin creates a vandermonde matrix of the vector (0,0,n) and outputs the entry that consists of n^2

function s = g(n)
    a = vander([0,0,n]);
    s = a(3,1)
end

This function creates the inverse of a hilbert matrix of size n where the top left element is always n^2

function s = g(n)
    a = invhilb(n);
    s = a(1);
end
flawr
  • 43.9k
  • 7
  • 104
  • 249