Hi, I have an excel file with complex numbers and I want to solve some simultaneous equations with them. I tried creating a for loop that imports row i from columns 11,12,13,14 and assigns them to a variable and then solves the needed simultaneous equations though it seems to not give any output. For reference, this works when i do it with a single case i.e. get rid of the loop and replace all i with a specific row e.g. 1, but how do I iterate it to complete it several times?
For[i = 1; i < 3, i++,
x = Import[
"C:\\Users\\Laptop\\simultaneous.xlsx",
{"Data", 1, i, 11}];
y = Import[
"C:\\Users\\ Laptop\\simultaneous.xlsx",
{"Data", 1, i, 12}];
z = Import[
"C:\\Users\\Laptop\\simultaneous.xlsx",
{"Data", 1, i, 13}];
m = Import[
"C:\\Users\\Laptop\\simultaneous.xlsx",
{"Data", 1, i, 14}];
eq1 = x == a + (y*z*b)/(1 - b^2);
eq2 = m == b + (y*z*a)/(1 - a^2);
NSolve[eq1 && eq2, {a, b}]]
By itself For does not give any output, as is mentioned in the documentation under Details:
You would have to add code to save the results from each row. But it might be easier to use Table instead of For. That would produce an output with the row results in a list.
I’m having some difficulty with the map function. Right now my code looks like this:
ClearAll["Global`*"]
e = Import[
"C:\\Users\\simultaneous_2.xlsx", \
{"Data", 1, {1, 2}, 18}];
x = ToExpression@e;
f = Import[
"C:\\Users\\simultaneous_2.xlsx", \
{"Data", 1, {1, 2}, 19}];
y = ToExpression@f;
g = Import[
"C:\\Users\\simultaneous_2.xlsx", \
{"Data", 1, {1, 2}, 20}];
z = ToExpression@g;
h = Import[
"C:\\Users\\simultaneous_2.xlsx", \
{"Data", 1, {1, 2}, 21}];
m = ToExpression@h;
eq1 = x2 == a + (y2*z2*b)/(1 - b^2);
eq2 = m2 == b + (y2*z2*a)/(1 - a^2);
fn = NSolve[eq1 && eq2, {a, b}];
So currently x,y,z and m are arrays of length 2. How would I use map on this though? I can’t directly map Nsolve because there is no input to that function. I am thinking I would have to use map on x,y,z,m e.g.
x[[i]]=x[[i]]
Map[x, {1, 2}]
but this does not seem to work. Any input would be appreciated