Matlab A Taylor series expansion is When f(x) is expanded at a local point x0=0,
ID: 3541733 • Letter: M
Question
Matlab
Explanation / Answer
#cos_maclaurin.m
function val = cos_maclaurin(x,deg)
val = 0;
sign =1;
i =0;
while i<=deg
val = val + (sign*( (x^i)/factorial(i)));
i=i+2;
sign = sign*-1;
end
end
#draw_cos_maclaurin.m
x= linspace(0,4*pi);
y1 = cos(x);
y2 = arrayfun(@cos_maclaurin, x, linspace(6,6));
y3 = arrayfun(@cos_maclaurin, x, linspace(8,8));
y4 = arrayfun(@cos_maclaurin, x, linspace(10,10));
subplot(2,2,1);
plot(x,y1);
title('Subplot 1: cos(x)');
subplot(2,2,2);
plot(x,y2);
title('Subplot 2: cos maclaurin(x,6)');
subplot(2,2,3)
plot(x,y3);
title('Subplot 3: cos maclaurin(x,8)');
subplot(2,2,4)
plot(x,y4);
title('Subplot 4: cos maclaurin(x,10)');
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.