For this question, I think you should use a for loop and check each number one by one. If you use 'n' in your expression, the result is in terms of 'n'. If you use a number instead of 'n', it will give you the result.
Note: using 'syms' and 'symsum' is not the best way to do this, but I wanted to help you with a code that included the one you already wrote.
Try this:
L = 50; % define L, I chose 50 randomly.
syms k
largest_n = 0; % the largest one we know so far is 0.
for n = 1:sqrt(L)
% we are trying numbers one by one (going from 1 to sqrt(L)),
% I am going only up to sqrt(L) because values greater than this
% cannot satisfy our condition by definition. You can start from
% L as well, but it will slow down your code since it is performing
% extra calculations for nothing.
F1 = symsum(k^2, k, 1, n); % F1 is a number, but the variable type is 'symbol'
F1 = double(F1); % change the type of F1 to 'double' so that we can do comparisons.
if F1 < L % if the calculated number is smaller than the desired number
largest_n = n;
% the largest n satisfying our condition that we know of is n.
% if we find a larger n later in the loop, we will change this.
end
end