S.O.S. Mathematics CyberBoard Forum Index S.O.S. Mathematics CyberBoard
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
c++ to Mathematics

 
Post new topic   Reply to topic    S.O.S. Mathematics CyberBoard Forum Index -> Computer Science
View previous topic :: View next topic  
Author Message
dirbax
Member


Joined: 28 Feb 2009
Posts: 10

PostPosted: Fri, 6 Mar 2009 22:17:43 UTC    Post subject: c++ to Mathematics Reply with quote

Hi , is it possible to transform the following code to math

int F( int n )
{
int r=0;
int mid=n/2;
for( int i=0 ; i<n ; i++)
{
if( i<mid) r+=1 ;
if( i==mid) r*=2 ;
if( i>mid) r=pow(r,3) ;
}
return r ;
}

and is this correct ? www.dirbax.com/inventions/dimd-dynamic-intelligent-mathematical-design-/practical-example-1.html

thanks
Back to top
View user's profile Send private message
aswoods
S.O.S. Oldtimer


Joined: 23 Feb 2009
Posts: 289
Location: Adelaide, Australia

PostPosted: Sat, 7 Mar 2009 00:21:56 UTC    Post subject: Reply with quote



Your C code will only work for a tiny range of values, and I would replace "pow" with r*r*r
Back to top
View user's profile Send private message
dirbax
Member


Joined: 28 Feb 2009
Posts: 10

PostPosted: Sat, 7 Mar 2009 14:48:35 UTC    Post subject: Reply with quote

Thanks astwoods , would you mind to explain me how did you find it ?
Back to top
View user's profile Send private message
dirbax
Member


Joined: 28 Feb 2009
Posts: 10

PostPosted: Sat, 7 Mar 2009 16:25:15 UTC    Post subject: Reply with quote

What about this function


int F( int n , int a, int b )
{
int r=0;
int mid=(a+b)/2;
for( int i=0 ; i<n ; i+=2, mid++)
{
if( i<mid ) r++ ;
if( i<mid && i>a ) r-- ;
if( i==mid ) r=r/2 ;
if( i>mid || i<b ) r=sqrt(r) ;
}
return r ;
}
Back to top
View user's profile Send private message
laracroft
S.O.S. Newbie


Joined: 03 Nov 2009
Posts: 3

PostPosted: Wed, 4 Nov 2009 05:51:57 UTC    Post subject: Reply with quote

Hi Dirbax,
Me Laracroft,
I read your post and found no incompatibility converting code to math.
Only change you should do is change the type of variable int r to long r.
Stay connected.
_________________
usb flash drive
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    S.O.S. Mathematics CyberBoard Forum Index -> Computer Science All times are UTC
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Contact Us | S.O.S. Mathematics Homepage
Privacy Statement | Search the "old" CyberBoard

users online during the last hour
Powered by phpBB © 2001, 2005-2009 phpBB Group.
Installation and all modifications: H. Knaust
Copyright © 1999-2009 MathMedics, LLC. All rights reserved.
Math Medics, LLC. - P.O. Box 12395 - El Paso TX 79913 - USA