# Error using Solve[ ] for an equation?

Posted 6 days ago
193 Views
|
5 Replies
|
1 Total Likes
|
 Could you please help me? n = Input["n=?"]; h = 2/n; Table[u[0, j] = 0, {j, 1, n}]; Table[u[n, j] = j*h*(2 - j*h), {j, 1, n}]; Table[u[i, 0] = 0, {i, 1, n}]; Table[u[i, n] = i h, {i, 0, Floor[n/2]}]; Table[u[i, n] = 2 - i h, {i, Floor[n/2 + 1], n}]; eq = Table[ u[i + 1, j] + u[i - 1, j] + u[i, j + 1] + u[i, j - 1] - 4*u[i, j] == 0, {i, 1, n - 1}, {j, 1, n - 1}] eq1 = Flatten[eq] var = Table[u[i, j], {i, 1, n - 1}, {j, 1, n - 1}]; Solve[eq1, var] Error : Solve::ivar: {u[1,1],u[1,2]} is not a valid variable. 
5 Replies
Sort By:
Posted 6 days ago
 var needs to be a vector. Solve[eq1, Flatten@var] (* {{u[1, 1] -> 7/64, u[1, 2] -> 47/224, u[1, 3] -> 145/448, u[2, 1] -> 51/224, u[2, 2] -> 13/32, u[2, 3] -> 131/224, u[3, 1] -> 177/448, u[3, 2] -> 135/224, u[3, 3] -> 39/64}} *) 
Posted 6 days ago
 Thank you. I changed my code as follow: eq1 = Flatten[eq] var = Table[u[i, j], {i, 1, n - 1}, {j, 1, n - 1}]; var1 = Flatten[var]; Solve[eq1, var1] but I got these errors : Flatten::normal: Nonatomic expression expected at position 1 in Flatten[eq]. [out]: Flatten[eq] Table::iterb: Iterator {i,1,-1+n} does not have appropriate bounds. Solve::naqs: Flatten[eq] is not a quantified system of equations and inequalities. 
Posted 6 days ago
 What is eq? I cannot reproduce the error n = 4; h = 2/n; Table[u[0, j] = 0, {j, 1, n}]; Table[u[n, j] = j*h*(2 - j*h), {j, 1, n}]; Table[u[i, 0] = 0, {i, 1, n}]; Table[u[i, n] = i h, {i, 0, Floor[n/2]}]; Table[u[i, n] = 2 - i h, {i, Floor[n/2 + 1], n}]; eq = Table[ u[i + 1, j] + u[i - 1, j] + u[i, j + 1] + u[i, j - 1] - 4*u[i, j] == 0, {i, 1, n - 1}, {j, 1, n - 1}] eq1 = Flatten[eq] var = Table[u[i, j], {i, 1, n - 1}, {j, 1, n - 1}]; Solve[eq1, Flatten@var] eq1 = Flatten[eq] var = Table[u[i, j], {i, 1, n - 1}, {j, 1, n - 1}]; var1 = Flatten[var]; Solve[eq1, var1] Result is the same.