From 7364b2c4c5576652b41e092ce3d96cf7d1ab1833 Mon Sep 17 00:00:00 2001 From: dominic Date: Wed, 18 Nov 2020 18:01:42 +0100 Subject: [PATCH 1/2] Update 'README.md' --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b45626b..b0acf3a 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,16 @@ ResistorJS is a Javascript library intended to compose electronical resistors. ## Using Resistors in Code In order to instantiate an 100 Ohm resistor, we simply call `new Resistor(100)`. In order to compose several resistors, the composite resistor types `SeriesResistor` and `ParallelResistor` are available. -``` +```JS var r1 = new Resistor(100); var r2 = new Resistor(150); // Combining resistors var inSeries = r1.series(r2); // type: SeriesResistor var inParallel = r1.parallel(r2); // type: ParallelResistor +inSeries.getOhmage() // 250 +inParallel.getOhmage() // 60 + // Drawing to DOM r1.draw(div1); r2.draw(div2); From 215eb20a55766e9130f9c55c5dfe50a802bd7bf4 Mon Sep 17 00:00:00 2001 From: dominic Date: Wed, 18 Nov 2020 18:13:36 +0100 Subject: [PATCH 2/2] Update 'README.md' --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b0acf3a..c2fa23c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ var r2 = new Resistor(150); var inSeries = r1.series(r2); // type: SeriesResistor var inParallel = r1.parallel(r2); // type: ParallelResistor +// Computing resulting resistors inSeries.getOhmage() // 250 inParallel.getOhmage() // 60 @@ -19,5 +20,12 @@ r2.draw(div2); inSeries.draw(div3); inParallel.draw(div4); ``` -Calling `Resistor.draw(element)` generates an SVG from the constructed Resistor object. Above code would render something like this: -![Your browser cannot display images :(](imgs/tutorial.png) \ No newline at end of file +Calling `Resistor.draw(element)` generates an SVG from the constructed Resistor object. Above code will render something like this: +![Your browser cannot display images :(](imgs/tutorial.png) + +## Computing approximations +Sometimes, one wants to use ohmages in an electronical circuit that simply are not available. By cleverly combining a sufficient number of available resistors, one can approximate the needed values. For instance, using only 100Ohm and 100Ohm resistors, one can construct a (sufficiently close to) 127Ohm resistor like so: + +![Your browser can still not display images :(](imgs/127ohm.png) + +`main.js` contains an example application using dynamic programming that computes sufficiently good approximations for resistor values within a set range. \ No newline at end of file