MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

C++ to Mathematica

  • To: mathgroup at
  • Subject: [mg30812] C++ to Mathematica
  • From: Moranresearch at
  • Date: Wed, 19 Sep 2001 00:16:57 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

Could someone please help convert this C++ code to Mathematica 4.1. I am 
unfamiliar with the loop structures and commands of C++. Even if there are 
easier ways to do this in M4.1 ( which, by the way, I would like to know 
also) I want to reproduce this as closely as possible so I can verify the 
answer with the older C++ program.Thank you.

minErr = MAXERR; bestM = STARTM, numConvergence = 0
for(c0 = avgc0 -.5; c0 <= avgc0 +.5; c0 += 0.01){for M = -1.0; M <= 1.0; M 
{sum = 0.0; num = 0; c02 = c0 * c0;
sum+= fabs(sqrt(c02 - M * p *p)-c);num++;}}
if(num<=0) continue;
err = sum/((double)num;
if(err <minErr){
MinErr = err;
if(numConvergence==1) return STARTM;
return bestM

  • Prev by Date: Re: Help w/ Mathematica: simple stuff
  • Next by Date: Re: comma delimited files for input?
  • Previous by thread: Re: Option FactorComplete->False in FactorInteger
  • Next by thread: RE: C++ to Mathematica