Resistance calculator: Difference between revisions

Added 11l [RPN]
m (Thundergnat moved page Resistance Calculator to Resistance calculator: Follow normal task title capitalization policy)
(Added 11l [RPN])
Line 44:
8.000 7.200 0.900 6.480 | | r
6.000 10.800 1.800 19.440 | r
 
=={{header|11l}}==
{{trans|Python}}
===RPN===
<lang 11l>T Resistor
Float resistance
voltage = 0.0
Resistor? a
Resistor? b
Char symbol
 
F (resistance = 0.0, Resistor? a = N, b = N; symbol = Char(‘r’))
.resistance = resistance
.a = a
.b = b
.symbol = symbol
 
F.virtual.new res() -> Float
R .resistance
F.virtual.new setVoltage(Float voltage) -> N
.voltage = voltage
F current()
R .voltage / .res()
F effect()
R .current() * .voltage
F report(level = ‘’) -> N
print(‘#4.3 #4.3 #4.3 #4.3 #.#.’.format(.res(), .voltage, .current(), .effect(), level, .symbol))
I .a != N {.a.report(level‘| ’)}
I .b != N {.b.report(level‘| ’)}
 
T Serial(Resistor)
F (Resistor a, b)
.a = move(b)
.b = a
.symbol = Char(‘+’)
 
F.virtual.override res() -> Float
R .a.res() + .b.res()
 
F.virtual.override setVoltage(Float voltage) -> N
V ra = .a.res()
V rb = .b.res()
.a.setVoltage(ra / (ra + rb) * voltage)
.b.setVoltage(rb / (ra + rb) * voltage)
.voltage = voltage
 
T Parallel(Resistor)
F (Resistor a, b)
.a = move(b)
.b = a
.symbol = Char(‘*’)
 
F.virtual.override res() -> Float
R 1 / (1 / .a.res() + 1 / .b.res())
 
F.virtual.override setVoltage(Float voltage) -> N
.a.setVoltage(voltage)
.b.setVoltage(voltage)
.voltage = voltage
 
F build(s)
[Resistor] stack
L(word) s.split(‘ ’)
I word == ‘+’
Resistor p = stack.pop()
stack.append(Serial(p, stack.pop()))
E I word == ‘*’
Resistor p = stack.pop()
stack.append(Parallel(p, stack.pop()))
E
stack.append(Resistor(Float(word)))
R stack.pop()
 
Resistor node = build(‘10 2 + 6 * 8 + 6 * 4 + 8 * 4 + 8 * 6 +’)
print(‘ Ohm Volt Ampere Watt Network tree’)
node.setVoltage(18.0)
node.report()</lang>
 
=={{header|CoffeeScript}}==
1,480

edits