function c = relation( n )if n==0 c = 1;elseif n==1 syms x c = [x 0];else syms x c = ((2*n-1)*x*[relation(n-1),0] - (n-1)*[0,0,relation(n-2)])/n; sum(c)endn=8m=n+1;xval=linspace(-1,1,5000)I=trapsum(polyval(relation(n),xval).*polyval(relation(m),xval),-1,1);
Gives the following output:
??? Error using ==> polyvalInputs to polyval must be floats, namely single or double.Error in ==> polyval at 63y = zeros(siz_x, superiorfloat(x,p));
What needs to be done to ensure that the output for the recurrence relation is a double?
I mean, in the function, we have syms x but this is to acquire the polynomial in analytic form. It's not necessary in this case but I need to plot it later on. The main issue I have is evaluating the integral using trapsum but I would need to do both; plot for various n, evaluate the integral.
Best Answer