0

Using MATLAB I want to calculate the limit of the sequence below. $$ a(n)=\frac{n^2+1}{3n^2+1} $$ $$ \lim_{(n\to\infty)}a(n)=? $$ At first I thought \

syms n
a(n)=(n^2+1)/(3*n^2+1);

limit(a(n),'n',inf)

would solve the problem.

However, this couldn't be the answer because the limit is calculated where n is a real number here, while n should be only the natural numbers. So I think I should use 'while' loop, but I can't figure out how I should use it. Any suggestions please?

Cashman
  • 43
  • 2
    As far I understand, infinity it isn't natural neither real valued, its a concept and not a number, so for your purposes, while $n$ is not in the complex numbers, you could use equivalently that $n \to \infty$ without having to care if $n$ is a natural number or if its a real number, the succession will converge (if it does), to the same answer. – Joako Apr 10 '23 at 02:47
  • If n is a natural number, then why not define it specify it as such via: syms n positive integer? You'll get exactly the same answer due to the reasons mentioned by @Joako. – horchler Apr 10 '23 at 17:41

1 Answers1

1

If you want to use the while loop, try to reduce the limit value to a tolerance range using $a(n)>a(n+1)$ for any $n\geq1$. Here is an example:

n = 1;
an = (n^2 + 1)/(3*n^2 + 1);
an_prev = an;

while true n = n + 1; an = (n^2 + 1)/(3*n^2 + 1); if abs(an - an_prev) < 1e-256 break; end an_prev = an; end disp(an);

adzetto
  • 344
  • 1
  • 12