Looking at this more closely, I noticed Y’(Y) is actually a continuous linear function, evaluating to Y’=(652-Y) at every point. Using this equation instead would cut your code down somewhat.
Also: the apostrophe (or single quote) might be illegal as part of a variable name. You’d better give it a name that only consists of alphabet characters. Underscores are probably OK. Periods perhaps. Anything else will probably bork. Only use numbers in varnames after an alphabetic char.
Disclaimer: I do not actually speak C (Arduino or otherwise).