Register to reply

Mathematica: looping using Module

by kaizen.moto
Tags: looping, mathematica, module
Share this thread:
kaizen.moto
#1
Oct24-11, 05:28 AM
P: 99
Dear all,

I have difficulty to solve this code which involves looping,

In [1] := m = 1; n = 1 ; A = -1 ; B = 5 ;
In [2] := m = 1; n = 3 ; A = 8 ; B = -2 ;
In [3] := m = 1; n = 5 ; A = 9 ; B = 7 ;
In [4] := m = 3; n = 1 ; A = -2 ; B = 8 ;
In [5] := m = 3; n = 3 ; A = 4 ; B = 3 ;
In [6] := m = 3; n = 5 ; A = 9 ; B = -1 ;
In [7] := m = 5; n = 1 ; A = 6 ; B = 9 ;
In [8] := m = 5; n = 3 ; A = 2 ; B = 1 ;
In [9] := m = 5; n = 5 ; A = 3 ; B = -7 ;

Method 1:
In [10] := qsolve := Module[{mat, A, B, m, n}, Table[mat = A + B, {m, 1, 5, 2}, {n, 1, 5, 2}]]

Method 2:
In [11] := qsolve := Module[{mat, A, B, m, n}, Clear[mat,A,B]; Do[mat = A + B; Print[mat], {m, 1, 5, 2}, {n, 1, 5, 2}]]

I have tried to use both method1 and method2 but still failed.

Iam expecting the answer to be {4,6,16},{6,7,8},{15,3,-4}

Please let me know how to fix this code.

Many thanks for any help.
Phys.Org News Partner Science news on Phys.org
Wildfires and other burns play bigger role in climate change, professor finds
SR Labs research to expose BadUSB next week in Vegas
New study advances 'DNA revolution,' tells butterflies' evolutionary history

Register to reply

Related Discussions
Mathematica: working with Module for 2 variables. Math & Science Software 2
Need some assistance with Mathematica Module Math & Science Software 7
Need help with looping Math & Science Software 5
Beginner to Mathematica's question! using Module! Math & Science Software 1
Looping without running out of memory Computing & Technology 12