Let's start off with some basic maths with circuits:
If the resistances are in a series, they have:
R[SIZE="1"]s[/SIZE] = R[SIZE="1"]1[/SIZE] + R[SIZE="1"]2[/SIZE] + R[SIZE="1"]3[/SIZE] + ... + R[SIZE="1"]n[/SIZE]
If they are in a parallel, they are:
1/R[SIZE="1"]p[/SIZE] = 1/R[SIZE="1"]1[/SIZE] + 1/R[SIZE="1"]2[/SIZE] + 1/R[SIZE="1"]3[/SIZE] + ... + 1/R[SIZE="1"]n[/SIZE]
I'd really recommend something here. Get a fraction-class to do the parallel.
Well, theory's okay. Right? I'd suppose this problem occurs for your code:
How to create a function which first calculates the parallel and then the parallel's value + the other one?
Well, parallel is first off, summing the reciprocals of the resistances in the parallel together, then take the reciprocal of that value.
Now, take that reciprocal and add it with the other resistance, then you get the total resistance, ya?
Hmm. What I'm thinking about, is making the thing like this:
Make a list with the resistances. To get parallels and series together, you'll most likely use a 2-dimensional list.
Example:
We have a combination like this:
(1, 4, 9)
(5, 4)
(6)
Where the parentheses are in series, and the rows are in parallel. A simple function to do this, can be made up by this:
So far, so good.
Now, let's say there's a parallel within the series, like this:
(1, x, 9)
(5, 4)
(6)
where x is:
(2 + 3)
(5)
(7)
(11)
Now, we have to calculate x whenever we come to that value. Do that by the following:
I'm unsure on how to apply this to Java however. Can an array/ArrayList contain two different elements?
Edit: Interesting work though. I'll check it out how I'd fix this in CLISP, then add it in a spoiler when done. If you know CLISP, that is.
If the resistances are in a series, they have:
R[SIZE="1"]s[/SIZE] = R[SIZE="1"]1[/SIZE] + R[SIZE="1"]2[/SIZE] + R[SIZE="1"]3[/SIZE] + ... + R[SIZE="1"]n[/SIZE]
Series
If they are in a parallel, they are:
1/R[SIZE="1"]p[/SIZE] = 1/R[SIZE="1"]1[/SIZE] + 1/R[SIZE="1"]2[/SIZE] + 1/R[SIZE="1"]3[/SIZE] + ... + 1/R[SIZE="1"]n[/SIZE]
I'd really recommend something here. Get a fraction-class to do the parallel.
Parallel
Well, theory's okay. Right? I'd suppose this problem occurs for your code:
Combination
How to create a function which first calculates the parallel and then the parallel's value + the other one?
Well, parallel is first off, summing the reciprocals of the resistances in the parallel together, then take the reciprocal of that value.
Now, take that reciprocal and add it with the other resistance, then you get the total resistance, ya?
Hmm. What I'm thinking about, is making the thing like this:
Make a list with the resistances. To get parallels and series together, you'll most likely use a 2-dimensional list.
Example:
We have a combination like this:
(1, 4, 9)
(5, 4)
(6)
Where the parentheses are in series, and the rows are in parallel. A simple function to do this, can be made up by this:
Code:
//list[x][y];
sum = 0;
for (x = 0; x < length(list); x++){
xsum = 0;
for (y in list[x]{
xsum += y;
}
sum += reciprocal(xsum);
}
return reciprocal(sum);So far, so good.
Now, let's say there's a parallel within the series, like this:
(1, x, 9)
(5, 4)
(6)
where x is:
(2 + 3)
(5)
(7)
(11)
Now, we have to calculate x whenever we come to that value. Do that by the following:
Code:
//list[x][y];
function calculate_resistance(list){
sum = 0;
for (x = 0; x < length(list); x++){
xsum = 0;
for (y in list[x]{
if (is_list(y))
xsum += calculate_resistance(y);
else
xsum += y;
}
sum += reciprocal(xsum);
}
return reciprocal(sum);
}I'm unsure on how to apply this to Java however. Can an array/ArrayList contain two different elements?
Edit: Interesting work though. I'll check it out how I'd fix this in CLISP, then add it in a spoiler when done. If you know CLISP, that is.


![[Image: serieske3.png]](http://img142.imageshack.us/img142/8052/serieske3.png)
![[Image: paralleltv9.png]](http://img104.imageshack.us/img104/3774/paralleltv9.png)
![[Image: combosp1.png]](http://img104.imageshack.us/img104/2460/combosp1.png)