# How can I use the DiscretePlot and LogPlot?

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:

iv1=a[0]==1;
iv2=a[1]==1;
rr=a[n]==a[n-1]+2*a[n-2];
sol=RSolve[{rr,iv1,iv2},a[n],n] // Simplify
a[n_]=a[n]/.sol[[1]];
Print[a[2],"   ",a[3],"   ",a[4],"   ",a[5]]
Print[a[50]]
DiscretePlot[a[n],{n,1,20}]
LogPlot[a[n],{n,1,20}]


• Is this what you want?: DiscretePlot[a[n], {n, 1, 20}, ScalingFunctions -> "Log"] May 2, 2020 at 0:53
• This is what I get (commenting out the Print statements): i.stack.imgur.com/Hg4Wb.png . I don't get the error you describe. May 2, 2020 at 0:56
• @MichaelE2 I thought he wanted to plot log(a(n)) vs. n. I get different result from your discretePlot command. Is mine wrong? May 2, 2020 at 0:58
• @Nasser I was just looking into what might explain it...haven't found the answer yet. May 2, 2020 at 0:59
• 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" May 2, 2020 at 1:01

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]


• I erased the last two lines from my code but it stills give me the same message:"Syntax :Incomplete expression;more input is needed" May 2, 2020 at 1:03
• @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. May 2, 2020 at 1:08
• 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}] May 2, 2020 at 1:38
• @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. May 2, 2020 at 1:48
• 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 May 2, 2020 at 1:59