For matlab I have part 1 and most of 2 i cant figure out ho

For matlab - I have part 1 and most of #2 (i cant figure out how to add step size), but I dont know how to do #3 any help would be great!!

1) cos_maclaurin.m
This file is a general function so that, for example, a functional call of cos_maclaurin(pi/4, 6) should return the value of cos(/4) from the expansion in with a polynomial degree or order of 6.

(2) draw_cos_maclaurin.m
This file is a script that draw four subplots, one is cos(x) by calling cos() directly in Matlab and the other three are approximated curves by calling the above function cos_maclaurin(), with which the degree or order of the polynomial is 6, 8, 10 respectively and step size of pi/16. The range of x in the four subplots should be [0, 4]. Compare the results between cos() and cos_maclaurin() with different orders.

(3) draw_cos_deriv_FFD.m
This file is a script that draws four subplots. The first subplot is sin(x) by calling sin() directly in Matlab. Then approximate the first derivatives of cos(x) by using the Forward Finite Difference (FFD) approach to estimate based on cos(), with the step sizes of pi/16, pi/32, and pi/64 respectively. Plot the errors between FFD estimations and the true values of sin(x), e.g. plot(x, FFD+sin(x)), in the other three subplots. The range of x in the four subplots should be [0, 4]. Compare the subplots of errors with different step sizes.

Solution


x = linspace(0,4*pi);
h1=pi/16;
h2=pi/32;
h3=pi/64;
y1 = -sin(x);
y2 = (h1/2)+(2*eps/h1);
y3 = (h2/2)+(2*eps/h2);
y4 = (h3/2)+(2*eps/h3);
figure
subplot(2,2,1)
plot(x,y1)
title(\'Subplot 1: sin(x)\')

subplot(2,2,2)
plot(x,y2)
title(\'Subplot 2: h1\')

subplot(2,2,3)
plot(x,y3)
title(\'Subplot 3: h2\')

subplot(2,2,4)
plot(x,y4)
title(\'Subplot 4: h3\')

For matlab - I have part 1 and most of #2 (i cant figure out how to add step size), but I dont know how to do #3 any help would be great!! 1) cos_maclaurin.m Th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site