Hi, I have to put a section in loop to find the following :

Given that I know an i/p analogue voltage on A2,A3,A4, that corrisspond to Vin, V50 and VL.

Then the following needs to be calculated:

A.....V_{RL2}^{2} + V_{XL}^{2} = V_{L}^{2} and rearranging, then,

B......V_{XL}^{2} = V_{L}^{2} - V_{RL}^{2}

Also from a vector diagram

C.....(V_{50} + V_{RL}^{2}) + V_{XL}^{2} = V_{in}^{2}

Substituting (1) into (2) then;

D.....V_{RL} = V_{in}^{2} - V_{50}^{2} - V_{L}^{2}/ 2 x V_{50}

E.....R_{L} = V_{RL} X 50 / V_{50} and

F.....X_{L} = V_{XL} X 50 / V_{50}

I am lost now, I have thought that the following would sort me out but it doesn't seem to be correct:

val1 = analogRead(val1); //Vin reads analog input A2 into val

val2 = analogRead(val2); //V50 reads analog input A3 into val

val3 = analogRead(val3); //VL reads analog input A4 into Val

val4 = sq(val1); //Vin squared

val5 = sq(val2); //V50 squared

val6 = sq(val3); //VL squared

val7 = (2 * val2); //2 x V50

val8 = (val4 - val6 - val7) / val7; //value of RL

val9 = sq(val8); //VRL squared

val10 = (val3 - val8); //VXL squared

val11 = sqrt(val10); //value of XL

lcd.setCursor(11, 2);

lcd.print(val11);

I am an old codger at 70 and this is driving bonkers, greyer and her indoors is looking up the divorce paper's,

It's taken me two hours to write this. The rest of my program works fine and I find it helps keep the grey matter going.

Can some kind gent save my bacon. Thanks