stuck on taylor seires
The problem: how do I make the sum = the calculated values added together
Should I use another "for loop" or maybe a "while loop"?
Or have I gone about the code completely wrong?
Should I use another "for loop" or maybe a "while loop"?
Or have I gone about the code completely wrong?
x=input('value of x:');
n=input('number of interations:');
i=0:n;
for k=1:n
tscos(1,k)=((-1)^(i))*((x^(i*2))/(factorial(2*i)));
end
0
Comments
you have a couple options:
x=input('value of x:'); n=input('number of interations:'); i=0:n; acc = 0; for k=1:n tscos(1,k)=((-1)^(i))*((x^(i*2))/(factorial(2*i))); acc = acc + tscos(1,k); endor
x=input('value of x:'); n=input('number of interations:'); i=0:n; for k=1:n tscos(1,k)=((-1)^(i))*((x^(i*2))/(factorial(2*i))); end acc = sum(tscos);acc will contain the sum, in either case.