1
$\begingroup$

I want to solve this equation:

X(i, j) + C*Y(i, j) = Z(i, j)

Where

i = 2    
j = 2
C = 5
X(i, j) = {{1, 1}, {1, 1}}
Y(i, j) = {{2, 2}, {2, 2}}

How can I get Mathematica to solve for values of Z(1, 1), Z(2, 1), Z(1, 2), Z(2, 2)?

I’m relatively new the Mathematica, and I’d like to solve these 4 equations, but I’d also like to be able to scale up i and j (to say, 10) without rewriting the code. Any syntax help would be very helpful. My code looks like this, but I can’t get Mathematica to find the solution.

Solve[
  Table[Subscript[X, i, j] - (C*Subscript[Y, i, j]), {i, 2}, {j, 2}] ==
    Table[Subscript[Z, i, j], {i, 2}, {j, 2}], {X, Y, Z}] 
$\endgroup$
3
  • $\begingroup$ See this: mathematica.stackexchange.com/questions/1004/… $\endgroup$
    – DavidC
    Commented Apr 16, 2013 at 3:01
  • $\begingroup$ Thanks David, but I already found that, it didn't answer my question. $\endgroup$
    – Thermoguy
    Commented Apr 16, 2013 at 3:28
  • 2
    $\begingroup$ If you just want to do the matrix operation, I think you can do something like this X = {{1, 1}, {1, 1}}; Y = {{2, 2}, {2, 2}}; C0 = 5; Z = X + C0 Y. $\endgroup$
    – user0501
    Commented Apr 16, 2013 at 4:28

1 Answer 1

4
$\begingroup$

Mathematica doesn't allow implicit definition of a matrix, so your Z should be defined as something like:

Z = {{z1, z2}, {z3, z4}};

For the case in which the order of Z is very high, you may prefer this kind of definition (just in case, I'd like to mention that something like Z(1, 1) doesn't make sense in Mathematica):

Z = Table[z[i, j], {i, 2}, {j, 2}];

Then, you seem to mix up Subscript and List. They're totally different. Personally, I suggest you not to use Subscript, since (I think) it's a compromise to the traditional form of math symbol and a somewhat pathological object in Mathematica. You'll find that List or just something like a[1, 1] = 1; a[1, 2] = 2; … more convinient when you get more familiar with Mathematica. Here your X and Y can be defined like this:

X = {{1, 1}, {1, 1}};
Y = {{2, 2}, {2, 2}};

The third problem in your code is that you choose capital letters for the name of variables, it's not a good choice since all the built-in functions in Mathematica are begun with capital letter so it may cause problems, and for your code, your C gets caught: it's a protected symbol. We can change it into c:

c = 5;

After running all the code above, we can solve your equation (by the way, your syntax of Solve is also wrong, it should not be {X, Y, Z} because X and Y are not unknown variables):

Solve[X + c Y == Z, Flatten@Z]
(* {{z1 -> 11, z2 -> 11, z3 -> 11, z4 -> 11}} 
   or
   {{z[1, 1] -> 11, z[1, 2] -> 11, z[2, 1] -> 11, z[2, 2] -> 11}} *)
$\endgroup$
2
  • $\begingroup$ Thanks for clarifying in your edit. I need to read and reread this a few times. I really appreciate your time. $\endgroup$
    – Thermoguy
    Commented Apr 16, 2013 at 3:48
  • 1
    $\begingroup$ @user6941 Everything's hard in the beginning :). $\endgroup$
    – xzczd
    Commented Apr 16, 2013 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.