Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Script for series expansion of sine
Date: Thu, 23 Apr 2009 04:26:01 +0000 (UTC)
Organization: University College Dublin
Lines: 29
Message-ID: <gsoqkp$b76$1@fred.mathworks.com>
References: <gsohrh$27i$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1240460761 11494 172.30.248.35 (23 Apr 2009 04:26:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 23 Apr 2009 04:26:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 87230
Xref: news.mathworks.com comp.soft-sys.matlab:534853


"Sean " <el_sean@yahoo.com> wrote in message <gsohrh$27i$1@fred.mathworks.com>...
> 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.

Sean,

The notes here http://www.derekroconnor.net/NA/LE/LE-2006-2.pdf  explain why your code gives the wrong answers.

I hope you read and digest all 14 pages of this homework solution.

Regards,

Derek O'Connor.