From: Walter Roberson on
Brittany Morgante wrote:

> n=1;
> % x=1
> cosval=1;
> for i=1:1:n
> cosval=((-1^n)*x^(2*n))/(factorial(2*n)) %formula found through google
> % cosval=cosval-(-1^(i+1)/factorial(2*n)) %formula made up using
> original formula on hw paper
> end

Biggest mistake in the new version: you are not summing the values. Each
loop iteration is going to overwrite the value from the previous loop.

This is in addition to the other poster who pointed out that your
confusion about i and n.
From: Brittany Morgante on
Walter Roberson <roberson(a)hushmail.com> wrote in message <ho6imr$3n1$1(a)canopus.cc.umanitoba.ca>...
> Brittany Morgante wrote:
>
> > n=1;
> > % x=1
> > cosval=1;
> > for i=1:1:n
> > cosval=((-1^n)*x^(2*n))/(factorial(2*n)) %formula found through google
> > % cosval=cosval-(-1^(i+1)/factorial(2*n)) %formula made up using
> > original formula on hw paper
> > end
>
> Biggest mistake in the new version: you are not summing the values. Each
> loop iteration is going to overwrite the value from the previous loop.
>
> This is in addition to the other poster who pointed out that your
> confusion about i and n.

with using only one of the formulas, how do you tell matlab to sum the values instead of only getting individual values for each term?
i havent been using the "newest" version of matlab, but the r2008a version because that is what the school that i am going to provides on all the computers.
x=1;
cosval=1;
for i=1:1:n
cosval=((-1^i)*x^(2*i))/(factorial(2*i))
end
From: Walter Roberson on
Brittany Morgante wrote:

> with using only one of the formulas, how do you tell matlab to sum the
> values instead of only getting individual values for each term?

total = 0
for IndexName = 1:FinalIndex
ThisValue = SomeExpressionInvolving_IndexName
total = total + ThisValue
end