MathGroup Archive 2010

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

Search the Archive

Re: Can you tell me what is wrong with this program

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110416] Re: Can you tell me what is wrong with this program
  • From: satya <ktsatyajit at gmail.com>
  • Date: Thu, 17 Jun 2010 02:03:48 -0400 (EDT)
  • References: <hv3nf8$ov$1@smc.vnet.net> <hv76ir$k1f$1@smc.vnet.net>

On Jun 15, 11:28 am, "Sjoerd C. de Vries" <sjoerd.c.devr... at gmail.com>
wrote:
> Satya,
>
> Before I start pointing out the many errors in your code, may I invite
> you to actually read the manual (at least the introductory parts)
> before asking questions? It's quite obvious that you haven't done so.
>
> The code you have written is far from Mathematica syntax, it's more
> like C with a few square brackets thrown in for good measures.
>
> - All built-in Mathematica functions should start with a capital
> letter. It's best, though not required, to start your own variables
> with a lowercase letter
> - the For syntax you use is a mixture of C and Mathematica. The body
> should be placed within the function, not outside. Check the doc page.
> - C is a reserved word in Mathematica
> - Abs needs square brackets
> - if and print should be capitalized
> - if you use Print this way everything will be run together
> - if [A > 0] is not the correct mathematica syntax. Should be
> If[condition , (* true branch *) , (* false branch *)]. The code that
> should be conditionally executed should be in the IF function not
> outside of it.
> - the two If's with K1 in them should be separated by a ; otherwise
> it's a multiplication
>
> Cheers -- Sjoerd
>
> On Jun 14, 12:52 am, satya <ktsatya... at gmail.com> wrote:
>
>
>
> > c = 0;
> > m = 0;
> > z = 0;
> > count = 0;
> > for [lc = 0, lc < 8, lc++]
> >  {
> >  lc = lc + 1;
> >  for[lm = -4, lm < 8, lm++]
> >    {
> >    lm = lm + 1;
> >    for [lz = -4, lz < 8, lz++]
> >      {
> >      lz = lz + 1;
> >      A = (2*(lc - lm)*(lc - lm)) + 4*lz*lz;
> >      B = -2*(lc + lm)*lz;
> >      C = 4*lc*lm;
> >      if [A > 0]
> >        if[(B*B - A*C) > 0]
> >        {
> >        K1 = (B + sqrt (B*B - A*E))/A;
> >        K2 = (B - sqrt (B*B - A*E))/A;
> >        e = abs (lc);
> >        m = abs (lm);
> >        z = abs (lz);
> >        L = c + m + z;
> >        if [K1 <= 0.707 && K1 > 0 , print[n, L, lc,   lm , =
 =
> lz, K1]]
> >          if [K2 <= 0.707 && K1 > 0 , print[n, L, lc,   lm=
 ,=
>   lz, K2]]
>
> >        }
>
> >      }
> >    }
> >  }
>
> > I get the following error
>
> > Out[5]= for[0, True, 0]
>
> > During evaluation of In[1]:= Set::wrsym: Symbol C is Protected. >>
>
> > Out[6]= {{{{for[-4, True, -4]^2 if[
> >       True] if[-48 C > 0] if[-E sqrt <= 0.707 && -E sqrt > 0,
> >       print[n, -4 abs, 2, -2, -2, -E sqrt]] if[
> >       E sqrt <= 0.707 && -E sqrt > 0,
> >       print[n, -4 abs, 2, -2, -2, E sqrt]]}}}}- Hide quoted text =
-
>
> - Show quoted text -

Thanks to all of you, sorry for the hurried post, I was desparately
trying do something and did not even seriously bother to make same
simple corrections when I imported the code which i wrote originally
for C.


  • Prev by Date: Re: how to scale text to a bounding rectangle?
  • Next by Date: Re: formatted table output to ascii file
  • Previous by thread: Re: Can you tell me what is wrong with this program
  • Next by thread: DiscretePlot