find all zeros of the riemann zeta function in matlab

To find all zeros of the Riemann zeta function in MATLAB, you can use the zeta and fzero functions.

First, you need to define the function whose zeros you want to find. For this, you can create an anonymous function that evaluates the Riemann zeta function for a given value of s:

main.m
zeta_fun = @(s) zeta(s);
25 chars
2 lines

Next, you can use the fzero function to find the zeros of this function. fzero searches for a point where the function changes sign. Since the Riemann zeta function has infinitely many zeros, you need to specify a range of values where you want to look for zeros. For example, to find all zeros with real part between 0 and 10, you can use:

main.m
zeros_fun = @(s) fzero(zeta_fun, [0 + 1i*s, 10 + 1i*s]);
57 chars
2 lines

Here, [0 + 1i*s, 10 + 1i*s] is the range of values where you want to search for zeros. This means that fzero will only look for zeros with real part between 0 and 10.

Finally, you can use a loop to iterate over all imaginary parts that you are interested in, and find the zeros for each value of s:

main.m
for s = 0.01:0.01:50
    zero = zeros_fun(s);
    disp(['Zero at: ', num2str(real(zero)), ' + ', num2str(imag(zero)), 'i']);
end
129 chars
5 lines

Here, s = 0.01:0.01:50 specifies the range of imaginary parts that you want to search. The loop iterates over all values in this range, and prints the real and imaginary parts of the corresponding zeros. Note that this code can take a long time to run, since the Riemann zeta function has infinitely many zeros, and fzero needs to be called many times to find them all.

gistlibby LogSnag