Azzera filtri
Azzera filtri

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

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

Risposte (1)

DUY Nguyen
DUY Nguyen il 3 Mar 2023
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');

Categorie

Scopri di più su Function Creation in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by