1

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]]}

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Vô Danh
  • 163
  • 5

1 Answers1

1

I assume you want something like the following:

Subscript[y, n][i_] := r Cos[i α] /. {r -> 3, α -> π/6}
Table[If[i == 1, Subscript[y, n][0], Subscript[y, n][i]], {i, 1, 9}]
(*{3, 3/2, 0, -(3/2), -((3 Sqrt[3])/2), -3, -((3 Sqrt[3])/2), -(3/2), 0}*)

Or in the same way:

Module[{s}, With[{k = 8}, s = k + 1; Table[If[i == 1, Subscript[y, n][0], Subscript[y, n][i]], {i, 1, s}]]]
(*{3, 3/2, 0, -(3/2), -((3 Sqrt[3])/2), -3, -((3 Sqrt[3])/2), -(3/2), 0}*)
E. Chan-López
  • 23,117
  • 3
  • 21
  • 44