How do we create a module in Mathics ? Same as MMA ?

40 views
Skip to first unread message

jhonai...@gmail.com

unread,
Jan 5, 2018, 11:10:31 AM1/5/18
to mathics-users

Following my MMA code:

Bisection[a0_, b0_, m_] :=
 Module[{},
  a = N[a0];  
  b = N[b0];  
  c = (a + b)/2; 
  k = 0; 
  output = {{k, a, c, b, f[c]}}; 
  While[k < m,
   If[ Sign[f[b]] ==  Sign[f[c]], 
    b = c, a = c; ]; 
   c = (a + b)/2; 
   k = k + 1; 
   output = Append[output, {k, a, c, b, f[c]}]; ]; 
  Print[NumberForm[
    TableForm[output, 
     TableHeadings -> {None, {"k", 
        "ak", 
        ck", 
        "bk", 
        "fck", 16]]; 
  Print["  c  = ", NumberForm[c, 16] ]; 
  Print[" DeltaC  = ", (b - a)/2]; 
  Print["fc = ", NumberForm[f[c], 16] ]; ]  

f[x_] = x^3 + 4 x^2 - 10; 
a = -1.0; 
b = 2.0;
Bisection[a, b, 30]; 
Plot[f[x], {x, -1.05, 2.05}, PlotRange -> {{-1.05, 2.05}, {-10, 15}}, PlotStyle -> Magenta] 

When I copy paste this in Mathics, I get the error "Syntax::sntxi: Incomplete expression; more input is needed (line 23 of "<notebook>")."
What am I doing wrong here, I thought anything coded in MMA should work directly without any changes in Mathics.
mathics_a00.nb
Reply all
Reply to author
Forward
0 new messages