Using Matlab Plot the function f(x)= e^x and the Maclaurin’s series expansion Using 6 terms, 8 terms and 10 terms
27 次查看(过去 30 天)
显示 更早的评论
Using Matlab Plot the function f(x)= e^x and the Maclaurin’s series expansion Using 6 terms, 8 terms and 10 terms
0 个评论
回答(1 个)
DUY Nguyen
2023-3-3
You can check this!
% Define the function and its Maclaurin series expansion
f = @(x) exp(x);
m6 = @(x) 1 + x + x.^2/2 + x.^3/6 + x.^4/24 + x.^5/120;
m8 = @(x) 1 + x + x.^2/2 + x.^3/6 + x.^4/24 + x.^5/120 + x.^6/720 + x.^7/5040;
m10 = @(x) 1 + x + x.^2/2 + x.^3/6 + x.^4/24 + x.^5/120 + x.^6/720 + x.^7/5040 + x.^8/40320 + x.^9/362880;
% Define the range of x values to plot
x = linspace(-3, 3, 100);
% Plot the function and its Maclaurin series expansions
plot(x, f(x), 'LineWidth', 2); hold on;
plot(x, m6(x), 'LineWidth', 2);
plot(x, m8(x), 'LineWidth', 2);
plot(x, m10(x), 'LineWidth', 2);
% Add a legend and labels
legend('f(x)', 'Maclaurin series (6 terms)', 'Maclaurin series (8 terms)', 'Maclaurin series (10 terms)');
xlabel('x');
ylabel('y');
title('Function f(x) = e^x and its Maclaurin series expansion');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!