> | ## HW 1, EECS 207A, UCI, Fall 2004. ## by Nasser Abbasi ## ## Problem: Find fourier series approximation to f(x)=x^2 and ## print the fourier coefficients. ## ## We see as more terms as added, we get better approximation to f(x). restart; with(plots): f:= x->x^2: N:=9; assume(n,integer); denomA:=int(cos(n*x)^2,x=-Pi..Pi): denomB:=int(sin(n*x)^2,x=-Pi..Pi): a:=seq( int(f(x)*cos(n*x),x=-Pi..Pi)/denomA,n=1..N); b:=seq( int(f(x)*sin(n*x),x=-Pi..Pi)/denomB,n=1..N); a0:=int(f(x),x=-Pi..Pi)/denomA: ff:=(n,x)-> a0/2 + sum( a[i]*cos(i*x),i=1..n) + sum( b[i]*sin(i*x),i=1..n); A:=array(1..3,1..3): k:=0: for n from 1 to 3 do for m from 1 to 3 do k:=k+1; str := sprintf("n = %d",k); A[n,m]:=plot( {f(x),ff(k,x)} , x=-Pi..Pi,title=str, linestyle=[DOT,DASH],thickness=[1,3], color=[red,black] ): end do: end do: display(A); |
> |
Warning, the name changecoords has been redefined
> |
> |
> |
> |
> |
> |
> |
> |