#C8.txt: Feb. 17, 2014. Gaussian quadrature and Help:=proc(): print(`LagP(L,x) , LIF(L,x), FindNC(n) `): print(`ApplyNC(f,x,n) , FindGauss(n) `): end: ###stuff from C7.txt #C7.txt (virtual class, distance learning) Help7:=proc(): print(`InterPol(L,x), InterPolF(f,x,L) `): end: #InterPol(L,x): #inputs a list of pairs [[x1,y1],[x2,y2], ..., [xn,yn]] of numbers (or symbols)! #and a variable name x,and outputs the unique polynomial of degree <= n-1 , #let's call it P(x), such that #P(x1)=y1, P(x2)=y2, ..., P(xn)=yn, #For example, InterPol([1,3],x); should give 3. InterPol:=proc(L,x) local P,n,i,a,var,eq: if not (type(L,list) and {seq(type(L[i],list),i=1..nops(L))}={true} and {seq(nops(L[i])-2,i=1..nops(L))}={0} ) then print(`The first argument`, L, `should be a list of pairs`): RETURN(FAIL): fi: n:=nops(L): P:=add(a[i]*x^i,i=0..n-1): var:={seq(a[i],i=0..n-1)}: eq:={seq(numer(subs(x=L[i][1],P)-L[i][2])=0,i=1..nops(L))}: var:=solve(eq,var): if var=NULL then RETURN(FAIL): else RETURN(subs(var,P)): fi: end: #InterPolF(f,x,L): #inputs an expression f, in the variable x, representing #a function, and a list L=[x1,...,xn], of numbers (or symbols) #outputs the unique polynomial of degree<= n-1, #let's call it P(x), such that #P(x1)=f(x1), ..., P(xn)=f(xn). For example, #InterPolF(x^3,[1,2,3,4],x); should return x^3 InterPolF:=proc(f,x,L) local i: InterPol([seq([L[i],subs(x=L[i],f)], i=1..nops(L))], x): end: ##end of C7.txt #LagP(L,x): inputs a list L=[x1,...,xn] # of numbers (or symbols) #and a variable name x, and outputs #the poly (x-x1)*(x-x2)* ...*x(x-xn) LagP:=proc(L,x) local i: mul(x-L[i],i=1..nops(L)): end: #LIF(L,x): inputs a list of pairs L #L=[[x1,y1], ..., [xn,yn]] and outputs #the unique polynomial in x of degree