Message Boards Message Boards

0
|
5153 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Issues with syntax procedural structures inside module

Posted 11 years ago
Hello, I am a beginner, I've written a method to calculate the unknown

 arriere[D_, R_] := Module[{n, a, b, x},
       a = D;
       b = R;
       n = Dimensions[a][[1]];
      
       For[j = n, j >= 1, j--,
         If[ a[[j, j]] == 0 , Break[]]
           x[[j]] = b[[j]]/a[[j, j]];
          For[i = 1, i <= j - 1,
     i++
                 b[[i]] = b[[i]] - a[[i, j]]*x[[j]];
          ];
        ];
      {x}];[/i][/i][/color]

but it returns me only the values ??of the input

k = {{1, 2, 3}, {0, -3, -6}, {0, 0, 1}}
l = {1, -3, 0}[/color]
arriere[k, l]
arriere[{{1, 2, 3}, {0, -3, -6}, {0, 0, 1}}, {1, -3, 0}]
POSTED BY: ayour aziz
2 Replies
Please use a more descriptive subject heading in future.
POSTED BY: Daniel Lichtblau
Posted 11 years ago
 In[1]:= calcularriere[d_, r_] := Module[{n, a, b, x},
    a = d;
    b = r;
    n = Dimensions[a][[1]];
    For[j = n, j >= 1, j--,
     If[a[[j, j]] == 0, Break[]];
      x = b/a[[j, j]];
     For[i = 1, i <= j - 1, i++,
       b = b - a[[i, j]]*x
     ]
    ];
   x];
k = {{1, 2, 3}, {0, -3, -6}, {0, 0, 1}};
l = {1, -3, 0};
calcularriere[k, l]

Out[4]= {20/3, -20, 0}
No space in name calcul arriere.
D is the derivative function name in Mathematica.
Dimensions[ a ] returns a list of all dimensions {3,3}.
No extra [ ] after variables.
Semicolon between each two expressions.

I hope this is correct and helps you.
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract