# Table mix with If function [closed]

Anyone could explain to me which problem is? after running the function "Table" combining with "If" as below, but the result is not a value instead.

 k:=8; n:=k+1; Alpha:=Pi/6; r:=3;
In[5]:= Subscript[y, n][i_] := r cos[i \[Alpha]]

In[6]:= Subscript[y, n] =
Table[if [i == 1, Subscript[y, n][0], Subscript[y, n][i]], {i, 1, n}]

Out[6]= {if[True, 3 cos[0], 3 cos[\[Pi]/6]],
if[False, 3 cos[0], 3 cos[\[Pi]/3]],
if[False, 3 cos[0], 3 cos[\[Pi]/2]],
if[False, 3 cos[0], 3 cos[(2 \[Pi])/3]],
if[False, 3 cos[0], 3 cos[(5 \[Pi])/6]],
if[False, 3 cos[0], 3 cos[\[Pi]]],
if[False, 3 cos[0], 3 cos[(7 \[Pi])/6]],
if[False, 3 cos[0], 3 cos[(4 \[Pi])/3]],
if[False, 3 cos[0], 3 cos[(3 \[Pi])/2]]}

• Try If[] instead of if [] all MM functions start with Capitals
– Lou
Jun 19, 2022 at 12:26
• #Lou, thank you so much. My basic fault :( Jun 19, 2022 at 12:35
• Note also that the cosine function is Cos and the imaginary unit is I. When you define constants, you don't need to use SetDelayed (:=); use Set (=) instead (see this FAQ). Jun 19, 2022 at 12:39
• Welcome to the Mathematica Stack Exchange. The introductory book written by the inventor is a good learning resource. There is a fast intro for math students as well as a fast intro for programmers to choose from.
– Syed
Jun 19, 2022 at 13:47

Subscript[y, n][i_] := r Cos[i α] /. {r -> 3, α -> π/6}

Module[{s}, With[{k = 8}, s = k + 1; Table[If[i == 1, Subscript[y, n][0], Subscript[y, n][i]], {i, 1, s}]]]