Using Matlab Plot the function f(x)= e^x and the Maclaurin’s series expansion Using 6 terms, 8 terms and 10 terms

4 次查看(过去 30 天)
Using Matlab Plot the function f(x)= e^x and the Maclaurin’s series expansion Using 6 terms, 8 terms and 10 terms

回答(1 个)

DUY Nguyen
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');

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by