# Matlab help

**URL:** <https://forum.kirupa.com/t/matlab-help/272809>\
**Category:** Uncategorized\
**Created:** [October 8, 2008, 5:16pm UTC](https://forum.kirupa.com/t/matlab-help/272809 "2008-10-08T17:16:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wo1olf](https://avatars.discourse-cdn.com/v4/letter/w/278dde/32.png) [@wo1olf](https://forum.kirupa.com/u/wo1olf)\
**Post date:** [October 8, 2008, 5:16pm UTC](https://forum.kirupa.com/t/matlab-help/272809/1 "2008-10-08T17:16:43Z")

</div>

[COLOR=black]i am trying to compute a suite with matlab;[/COLOR]  
[COLOR=black]the formula suite is [/COLOR]  
[FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Verdana][COLOR=black]_sn = 1 - (2_n\*(2_n-1)/(pi_pi))\*s1(n-1) \*[/COLOR][/FONT][/COLOR][/SIZE][COLOR=#228b22]  
[SIZE=2][FONT=Verdana][COLOR=black]\*where s0 = 2 \*[/COLOR][/FONT][/SIZE]  
[SIZE=2][FONT=Verdana][COLOR=black]_and n is between 1 and 15_[/COLOR][/FONT][/SIZE]

[SIZE=2][FONT=Verdana][COLOR=black]this is my code[/COLOR][/FONT][/SIZE]  
[SIZE=2][FONT=Verdana][COLOR=#000000]%loop from 2 to 16[/COLOR][/FONT][/SIZE]  
[/COLOR][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT]

```auto
 
for n =2:16
%term 0
 
s(1) = 2;
%compute the nest term
s(n) = 1 - (2*n*(2.*n-1)/(pi*pi))*s1(n-1) 
 
%display ther results
fprintf(' %2d %2d 
',n-1,s(n-1));
end

```

the problem is am having weird results with an alternating sign.  
ex for the 2 first terms in a normal calculation (outside the loop and using the same formula) give tthe following results:  
s1 = 5.947152654306489e-001  
s2 = 2.769129445167948e-001  
while inside the loop from the code above i get  
s1 = -1.431708e+000  
s2 = 5.351872e+000

Does any body know why i do get differents results or how can i fix this? :puzzled:  
[FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Verdana][COLOR=#000000]thnks[/COLOR][/FONT][/COLOR][/SIZE][COLOR=#228b22]  
[/COLOR][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT]
