# Then can the result of the general term formula be written in subsection form?

s[n_] = n^2 - 2 n + 3
RSolve[a[n + 1] == s[n + 1] - s[n], a[n], n]


The above example shows that the general term formula of the sequence should be in a piecewise form. When n==1, a 1==s 1=2, when n is greater than or equal to 2, a [n]=2n-3

The above code calculation result reported an error For some branches of the general solution, the given boundary
conditions lead to an empty solution

According to the characteristics of the summation formula. It is a quadratic function with constant term 3. So its general term formula must be in the form of subsection, that is, when n=1, its first term a 1==1, which can be calculated by a 1==s 1. When n is greater than or equal to 2, a [n]=2n-3 is calculated by a [n]==s [n] - s [n-1]. Obviously, when n=1, 2 * 1-3=- 1<>a 1, so finally a [n] should write its general term formula in the form of subsection.

The format in the picture is the final result I want • I think the problem is that RSolve expects a recurrence, and this is not in fact a recurrence. Though RSolve could give a more informative message I guess. Feb 14 at 14:41
• If you want take a moment to think about the following: you have asked 27 questions and you have accepted answers in only three of those. I am not suggesting that you should immediately accept @BobHanlon's answer here, it's actually good to wait for a bit in case others provide alternatives. What I want to tell you is that accepting answers is very helpful for future users who might face the same difficulties that you are right now. And, also, not accepting answers might discourage some people from offering their help.
– bmf
Feb 14 at 15:23
• Thanks for reminding Feb 14 at 23:35

Clear[a, n, s];

s[n_] = n^2 - 2 n + 3;

eqn = a[n + 1] == s[n + 1] - s[n] // Simplify

(* 2 n == 1 + a[1 + n] *)

a = 2;

a[n_] = SolveValues[eqn /. n -> n - 1, a[n]][]

(* -3 + 2 n *)


EDIT: For the revised question. Apparently, you want to use Piecewise. Also, you must specify a separately since you want it to have an inconsistent value. That is 2*(1) - 3 == -1 rather than 1

s[n_] = n^2 - 2 n + 3;
Clear[a];
(a[n_Integer?Positive] =
Piecewise[{{1, n == 1},
{RSolveValue[a[n + 1] == s[n + 1] - s[n], a[n], n] //
Simplify, n >= 2}}]) // TraditionalForm • Can you use the summation formula software to automatically calculate and write the general term formula in the form of subsection? Instead of manually specifying a  Feb 14 at 23:28
• In the question you specified that a = 2; otherwise, it would be s - s which evaluates to -1. I don't understand what you mean by "in the form of subsection". Feb 14 at 23:49
• According to the characteristics of the summation formula. It is a quadratic function with constant term 3. So its general term formula must be in the form of subsection, that is, when n=1, its first term a ==1, which can be calculated by a ==s . When n is greater than or equal to 2, a [n]=2n-3 is calculated by a [n]==s [n] - s [n-1]. Obviously, when n=1, 2 * 1-3=- 1<>a , so finally a [n] should write its general term formula in the form of subsection. Feb 15 at 0:01
• In two places in the question you state that a = 2; if that is not what you want, then edit the question to state the problem correctly. Feb 15 at 0:18
• All we know is the summation formula. Use this codes[n_] = n^2 - 2 n + 3 RSolve[a[n] == s[n] - s[n - 1], a[n], n] // FullSimplifyOnly a [n]=2n-3 is calculated, and a =2 is not calculated separately. So I put a  in it manually. Feb 15 at 0:43