2
$\begingroup$
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

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ 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. $\endgroup$ Feb 14 at 14:41
  • 2
    $\begingroup$ 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. $\endgroup$
    – bmf
    Feb 14 at 15:23
  • 1
    $\begingroup$ Thanks for reminding $\endgroup$
    – csn899
    Feb 14 at 23:35

1 Answer 1

5
$\begingroup$
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[1] = 2;

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

(* -3 + 2 n *)

EDIT: For the revised question. Apparently, you want to use Piecewise. Also, you must specify a[1] 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

enter image description here

$\endgroup$
8
  • $\begingroup$ 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 [1] $\endgroup$
    – csn899
    Feb 14 at 23:28
  • $\begingroup$ In the question you specified that a[1] = 2; otherwise, it would be s[1] - s[0] which evaluates to -1. I don't understand what you mean by "in the form of subsection". $\endgroup$
    – Bob Hanlon
    Feb 14 at 23:49
  • $\begingroup$ 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. $\endgroup$
    – csn899
    Feb 15 at 0:01
  • $\begingroup$ In two places in the question you state that a[1] = 2; if that is not what you want, then edit the question to state the problem correctly. $\endgroup$
    – Bob Hanlon
    Feb 15 at 0:18
  • $\begingroup$ 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 [1]=2 is not calculated separately. So I put a [1] in it manually. $\endgroup$
    – csn899
    Feb 15 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.