I am really new to mathematica and this will seem very basic, but the two last lines of the code do not work (the two prints work just fine), it gives me the error more input is needed(only for the DiscretePlot and LogPlot). The code is as follows:

sol=RSolve[{rr,iv1,iv2},a[n],n] // Simplify
Print[a[2],"   ",a[3],"   ",a[4],"   ",a[5]]

  • $\begingroup$ Is this what you want?: DiscretePlot[a[n], {n, 1, 20}, ScalingFunctions -> "Log"] $\endgroup$
    – Michael E2
    May 2, 2020 at 0:53
  • $\begingroup$ This is what I get (commenting out the Print statements): i.stack.imgur.com/Hg4Wb.png . I don't get the error you describe. $\endgroup$
    – Michael E2
    May 2, 2020 at 0:56
  • $\begingroup$ @MichaelE2 I thought he wanted to plot log(a(n)) vs. n. I get different result from your discretePlot command. Is mine wrong? $\endgroup$
    – Nasser
    May 2, 2020 at 0:58
  • $\begingroup$ @Nasser I was just looking into what might explain it...haven't found the answer yet. $\endgroup$
    – Michael E2
    May 2, 2020 at 0:59
  • $\begingroup$ I want to plot both graphs, the one with discrete and the one with log, but it gives me "Syntax :Incomplete expression;more input is needed" $\endgroup$ May 2, 2020 at 1:01

1 Answer 1


You can't use LogPlot on a[n] since a[n] only works on discrete values of its argument.

You could generate your own data and use ListLogPlot

data = Table[{n, a[n]}, {n, 1, 20}];
ListLogPlot[data, Joined -> True, Mesh -> All,  
        AxesLabel -> {"n", "log(a(n))"}, BaseStyle -> 12]

Mathematica graphics

  • $\begingroup$ I erased the last two lines from my code but it stills give me the same message:"Syntax :Incomplete expression;more input is needed" $\endgroup$ May 2, 2020 at 1:03
  • $\begingroup$ @JohnCarter The errors you get when you try to run your code again, due to redefinitions. Try to run the code each time from clean kernel, and you'll see you get no error. Each time you run the code, you need to do ClearAll before you run your code, due to how you wrote it. Always start your code fragment you are trying with ClearAll[...] to avoid such problems. $\endgroup$
    – Nasser
    May 2, 2020 at 1:08
  • $\begingroup$ As defined, a[n] "works" for non-integer values; however, the values are complex and do not display in a plot. The OP could use Plot[Abs[a[n]], {n, 1, 20}, ScalingFunctions -> "Log"] or LogPlot[Abs[a[n]], {n, 1, 20}] $\endgroup$
    – Bob Hanlon
    May 2, 2020 at 1:38
  • $\begingroup$ @BobHanlon You are right actually. But I think the "spirit" of these is that they are meant to be used for integer only $n$. I assumed so, since it look like standard difference equation to me, but I did not check that they generated complex for non-discrete values. But you do have a point there. $\endgroup$
    – Nasser
    May 2, 2020 at 1:48
  • $\begingroup$ Difference equations are frequently extended to non-integer values similar to the way that factorial functions are extended to non-integer values. Look at Fibonacci $\endgroup$
    – Bob Hanlon
    May 2, 2020 at 1:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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