1

f[k] = -(1/2)^k - ((1/4) (1 - sqrt[5]))^k/sqrt[5] + ((1/4) (1 + sqrt[5]))^k/sqrt[5] (and also f[k] = 0 when k = 1,2)

I need to make a lineplot of this function in k = 3,4,5,... ,20.

  1. why this does not plot my grpah?
  2. how to plot a graph of this function? (input is integer)
  3. how to deal with exceptions k=1, k=2?

enter image description here

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
jerryed
  • 135
  • 5

3 Answers3

5
Clear["Global`*"]

f[k_] = -(1/2)^k - ((1/4) (1 - Sqrt[5]))^k/Sqrt[5] + 
    ((1/4) (1 + Sqrt[5]))^k/Sqrt[5];

Show[
 Plot[Evaluate[Re@f[k]], {k, 4/5, 15}],
 DiscretePlot[f[k], {k, 1, 15}, PlotStyle -> Red],
 PlotRange -> {{0, 15.5}, Automatic},
 AxesOrigin -> {0, 0}]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
4
f[k_] = -(1/2)^k - ((1/4) (1 - Sqrt[5]))^k/
    Sqrt[5] + ((1/4) (1 + Sqrt[5]))^k/Sqrt[5];
ListPlot[Table[f[k], {k, 3, 20}], Joined -> True, Mesh -> All, 
 MeshStyle -> Red]

enter image description here

cvgmt
  • 72,231
  • 4
  • 75
  • 133
  • ok, so I changed my mind and re-stating my previous comment. Talk about epic timing!!! – bmf Mar 24 '22 at 01:51
4

To understand what you did wrong observe the differences in the colors between your code and mine. What do you see for the Sqrt function? Something is different.

Something is also different for the variable k. Have a close look.

There rest is fine. See the below:

f[k_] := -(1/2)^k - ((1/4) (1 - Sqrt[5]))^k/
   Sqrt[5] + ((1/4) (1 + Sqrt[5]))^k/Sqrt[5]

Array[f, 15];

ListPlot[%, PlotRange -> {0, 0.2}]

array

bmf
  • 15,157
  • 2
  • 26
  • 63
  • 1
    The time only 0:01 difference. – cvgmt Mar 24 '22 at 01:48
  • @cvgmt hahahaha yes. I also left a message, but deleted because people say we shouldn't write funny stuff, etc :-) I should have left it!!! – bmf Mar 24 '22 at 01:49