MatLab e^x Homework: Plot and Error Calc

  • Thread starter Thread starter sandbanana
  • Start date Start date
  • Tags Tags
    E^x Matlab
Click For Summary
SUMMARY

This discussion focuses on using MATLAB to plot the function e^x using a Taylor series expansion around 0 and calculating the error between the nth term and the actual values of e^-10 and e^10. The user also explores plotting sin(4*theta) with varying term expansions (2, 4, and 10 terms) and compares these plots to the actual function. The provided MATLAB code effectively computes the Taylor series expansion and displays the result, demonstrating a successful approach to the homework assignment.

PREREQUISITES
  • Familiarity with MATLAB programming environment
  • Understanding of Taylor series and their applications
  • Basic knowledge of trigonometric functions and their plots
  • Experience with error calculation in numerical methods
NEXT STEPS
  • Learn MATLAB plotting functions for visualizing mathematical functions
  • Study error analysis techniques in numerical approximations
  • Explore advanced MATLAB features for symbolic computation
  • Investigate Taylor series convergence and its implications
USEFUL FOR

Students and educators in mathematics or engineering fields, particularly those learning numerical methods and MATLAB programming for mathematical modeling and analysis.

sandbanana
Messages
8
Reaction score
0

Homework Statement



Plot e^x for -10 to 10 using a Taylor series about 0
find the error between the nth term and the actual value of e^-10 and e^10

plot sin(4*theta) using a 2 term expansion, a 4 term expansion and a 10 term expansion and constrast it with the plot of sin(4*theta)

The Attempt at a Solution



This is the first time I have ever opened MatLab and tried to do any sort of math programming. I suppose I need help in the logic of it or trying to trace what I am doing.

So far I have:

Code:
%This will compute the Taylor Series expansion of e^x for a user defined
%x value for the number of terms required by the user.  It will do this about the point
%a=0.  The result of the
%nth term will be compared to the computer generated value of e^xx = input ('Enter a value for x:'); % user input of which value to use for x
i = input ('Enter the non-zero number of terms for this Taylor Series expansion:'); %user input of number of terms to use

% g_n: the nth term in Taylor Series

k=1;    % initialize k

g_n=x^(k-1)/factorial(k-1);   % begin with the first term

g=g_n;

while  i>k; % let index increase until number of desired terms reached
 
    k=k+1;  % increase index by 1
    g_n=x^(k-1)/factorial(k-1);
    g=g+g_n; %add the next term in the series   
end
    
disp(g)

I changed my code to what is listed above and it seemed to help entirely.
 
Last edited:
Physics news on Phys.org
http://www.mathworks.com/help/toolbox/symbolic/taylor.html
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
2
Views
2K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
Replies
7
Views
3K