Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com calculating series

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 03-06-2011, 09:36 PM PM User | #1 sackstein Regular Coder   Join Date: Jan 2009 Posts: 160 Thanks: 40 Thanked 1 Time in 1 Post calculating series The question I am having problems with is the following: Write a method to compute the following series: m(i) = 4(1 - 1/3 + 1/5 -1/7 + 1/9 - 1/11 + ... + 1/(2i-1) - 1/(2i+1) here is the code I have put together so far: Code: ```public class series { public static double m(int i){ double num = 0; for (i = i;i>0;i--){ //infinite times starting at i num += 4*((1/(2*((double)i)-1))-(1/(2*((double)i)+1))); } return num; } public static void main(String args[]){ System.out.println("i m(i)"); for (int i=10;i<=100;i=i+10) System.out.println(i+" "+(m(i))); } }``` for some reason it is not displaying the correct results what am I missing? The expected print out is : i m(i) 10 3.04184 20 3.09162 etc but mine is starting at 3.809 Last edited by sackstein; 03-06-2011 at 09:46 PM..
 03-08-2011, 01:21 AM PM User | #2 spchinta New Coder   Join Date: Mar 2011 Location: USA Posts: 23 Thanks: 0 Thanked 1 Time in 1 Post Is the formula correct? With your logic in code I a1ways get this: i=10; num = 4(1/19 -1/21) i=9; num=4(1/17-1/19) i=8; num=4(1/15-1/17) i=7; num=4(1/13-1/15) i=6; num=4(1/11-1/13) i=5; num=4(1/9-1/11) i=4; num=4(1/7-1/9) i=3; num=4(1/5-1/7) i=2; num=4(1/3-1/5) i=1; num=4(1-1/3) Total will be 3.80952380952381 And with m(i) formula you gave above with m= 10, I always get m(10) = 1-1/3+1/5-1/7+1/9-1/11+1/13-1/15+1/17-1/19+1/21 it is not matched to 1/(2i-1) + 1/(2i+1). Please revise the formula once.. Last edited by spchinta; 03-08-2011 at 01:30 AM..

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 06:14 PM.