Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Script for series expansion of sine
Date: Thu, 23 Apr 2009 01:56:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 18
Message-ID: <gsohrh$27i$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1240451761 2290 172.30.248.37 (23 Apr 2009 01:56:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 23 Apr 2009 01:56:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1782552
Xref: news.mathworks.com comp.soft-sys.matlab:534843


Hello folks,

To begin with, I browsed through the archives looking for relevant posts to my question and found some related topics.  However, the posts were ill-structured and, appropriately, weren't answered.  Hopefully I can be a little more specific.

I'm trying to write a script to calculate the series expansion of sine with the inputs x (argument) and n.  Here's what I've thrown together so far:

% SINESERIES:  computes sin(x) from series expansion.
% A script to evaluate the series expansion of sine with the formula:
% sin(x) = x-(x^3/3!)+(x^5/5!)-... 
x = input('Enter the argument x:  ');
n = input('Enter the interval n:  ');
N = 1:1:n;     % Creates row vector with n elements, 1 at a time.
k = 2*N-1;    % For convenience with prod() function
j = N-1;        % For cleanup.
sinseries = ((-1).^(j)).*((x.^(k))./(prod(k)))
sum(sinseries)

My calculations aren't turning out at all correctly, short of x = 1, n = 1.  I've been toying with the equation to see if I translated it wrong, but I think the problem lies in how I'm expressing the series.  If anybody has some advice, I'd greatly appreciate it.  Thanks.