C++ to Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg30812] C++ to Mathematica
- From: Moranresearch at aol.com
- Date: Wed, 19 Sep 2001 00:16:57 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
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
+=0.01)
{sum = 0.0; num = 0; c02 = c0 * c0;
for(j=0;j<10;j++){
if{avgc0>0){
p=avgp[j]
c=avgc[j]
sum+= fabs(sqrt(c02 - M * p *p)-c);num++;}}
if(num<=0) continue;
err = sum/((double)num;
if(err <minErr){
bestc0=c0;
bestM=M
MinErr = err;
numConvergence++;}}}
if(numConvergence==1) return STARTM;
return bestM