Are you using “_i” as a notation for subscript? Subscripts in executable code need extra work. See the notebook attachment SubscriptedVariables101.nb in thread Global and local variables for suggestions.
For the second draft, try writing the code without subscripts.
If you mean “a_i” to be a variable name, that will not work in Wolfram Language. Underscore is a special character.
In[1]:= ?_
_ or Blank[] is a pattern object that can stand for any Wolfram Language expression.
_h or Blank[h] can stand for any expression with head h.