Using Matlab Plot the function f(x)= e^x and the Maclaurin’s series expansion Using 6 terms, 8 terms and 10 terms
Afficher commentaires plus anciens
Using Matlab Plot the function f(x)= e^x and the Maclaurin’s series expansion Using 6 terms, 8 terms and 10 terms
Réponses (1)
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');
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
