Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I NEED TO GENERATE A MATLAB CODE FOR THIS!! Write a user-defined function called

ID: 1811377 • Letter: I

Question

I NEED TO GENERATE A MATLAB CODE FOR THIS!!

Write a user-defined function called funct that takes two numbers x and N, where N isa positive integer and x real number in the interval (0 le x le 2 pi ). Your function should return the partial sum of cosines: QN(x)= cos(kx)/k2 = cos x/1 + cos 2x/22 + cos 2x/32 + ... + cos Nx/N2. Note that your function should print out a warning and exit if N is not a positive integer. Then write a main program that asks the user to input a positive number x takes five values of x in the interval (0 le x le 2 pi). For each value of x, use your function funct to compute the partial sine cosine sum for N values from 1 to 100 and place your values in a vector. Also compute the quantity Q = pi 2/6 - pi x/2 + x2/4 and place you values in another vector. Plot both QN (x) and Q(x) versus N on the same axis. Label the x-axis "Number of terms, N'', the y-axis "Partial Cosine Sum" and the title "Sinusoidal Series A". Remember to use legend to differentiate your plots and comment your program liberally. Next generate a vector of 200 values of x in the interval (0

Explanation / Answer

x=linspace(0,2*pi-.2,5);%5 values of x qn=zeros(100,5); for N=1:100 qn(N,:)=Qn1(x,N); end q=pi^2/6-pi*x/2+(x.^2)/4; q=ones(100,1)*q; plot(qn); hold all plot(q); legend('0','1.570','3.141','4.712','6.083','0','1.570','3.141','4.712','6.083') xlabel('Number of terms,N'); ylabel('partial cosine sum'); title('sinusoidal series A') function y=Qn1(x,N) y=0; for i=1:N y=y+cos(i*x)/(i^2); end end %%will sumbit part b in comment. I ran out time