Jeremy Bos
MA4635
Final
5.3)7)b)

Use the collocation method to find the approximate solution for Ex 15 
u(x)=x + (∫_(-1)^1) xtu(
              t) dt in terms of 2 sets of independent functions.

Remove["Global`*"]

n = 30;
ul = 1;
ll = -1;
Array[ph, {1, n}];
cvar = Table[(Subscript[c, i]), {i, n}];
et = Table[0, {n}] ;
as = Table[0, {n}] ;

ph[1, x_] := 1

Clear[k];  k = 0;
For[k = 3, k ≤ n - 1, 
      k += 2, 
ph[k, x] = 
        Cos[(N[(((k - 1))/2)])*x]
]

Clear[k]; k = 0;
For[k = 2, k ≤ n, 
      k += 2, 
ph[k, x] = 
        Sin[(N[(k/2)])*x]
]

s3[x_] = (∑_(i = 1)^n)((Subscript[c, i])*ph[i, x])

eu[x_] = 
      s3[x] - (x + (∫_ll^ul) x*t*
                s3[t] \[DifferentialD]t)

delta = N[((ul - ll)/(n - 1))]

Clear[k]
For[k = 1, 
      k ≤ n, k++, 
et[[k]] = 
        eu[ll + ((k - 1)*delta)]
]

et

soln = Solve[et == 0, cvar]

Clear[i, k]
For[k = 1, 
      k ≤ n, k++, 
as[[k]] = 
        (Subscript[c, k]) /. soln; Print[as[[k]]]
]

fas[x_] = (∑_(i = 1)^n) as[[i]]*ph[i, x]

Plot[{fas[x], 3*x}, {x, 2*ll, 2*ul}, 
      PlotStyle -> {{Hue[1]}, {Hue[0.6]}}]