-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCircuits.h
2228 lines (2023 loc) · 76.7 KB
/
Circuits.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// Created by Ryan.Zurrin001 on 12/15/2021.
//
#ifndef PHYSICSFORMULA_CIRCUITS_H
#define PHYSICSFORMULA_CIRCUITS_H
/**
* @class Circuits
* @details driver class for solving complex physics problems
* @author Ryan Zurrin
* @dateBuilt 3/3/2021
* @lastEdit 11/12/2022
*/
#include <iostream>
#include <utility>
#include "ElectricCurrent.h"
#include "ElectricPotential.h"
#include "ResistorNode.h"
#include "CapacitorNode.h"
#include "InductorNode.h"
#include "ElectroMagneticWaves.h"
static int circuits_objectCount = 0;
struct Battery {
double voltage;
double current;
double resistance;
double power;
Battery() {
voltage = 0.0;
current = 0.0;
resistance = 0.0;
power = 0.0;
}
Battery(double v, double c, double r, double p) {
voltage = v;
current = c;
resistance = r;
power = p;
}
void print() const {
cout << "Battery: " << endl;
cout << "voltage: " << voltage << endl;
cout << "current: " << current << endl;
cout << "resistance: " << resistance << endl;
cout << "power: " << power << endl;
}
};
struct CircuitNode {
vector<CapacitorNode<long double>> capacitorNodes;
vector<ResistorNode<long double>> resistorNodes;
vector<InductorNode<long double>> inductorNodes;
vector<Battery> powerNodes;
CircuitNode() {
capacitorNodes = {};
resistorNodes = {};
inductorNodes = {};
powerNodes = {};
}
CircuitNode(vector<CapacitorNode<long double>> c,
vector<ResistorNode<long double>> r,
vector<InductorNode<long double>> i,
vector<Battery> p) {
capacitorNodes = c;
resistorNodes = r;
inductorNodes = i;
powerNodes = p;
}
void print() {
cout << "CircuitNode: " << endl;
cout << "capacitorNodes: " << endl;
for (CapacitorNode capacitorNode : capacitorNodes) {
capacitorNode.print();
}
cout << "resistorNodes: " << endl;
for (ResistorNode resistorNode : resistorNodes) {
resistorNode.print();
}
cout << "inductorNodes: " << endl;
for (InductorNode inductorNode : inductorNodes) {
inductorNode.print();
}
cout << "powerNodes: " << endl;
for (Battery powerNode : powerNodes) {
//powerNode.print();
}
}
};
class Circuits:
public ElectricPotential,
public ElectromagneticWaves
{
public:
Circuits()
{
countIncrease();
}
explicit Circuits(long double val)
{
countIncrease();
}
/**
* @brief copy constructor
*/
Circuits(const Circuits& c)
: ElectricPotential(c) , ElectromagneticWaves(c) {
countIncrease();
}
/**
* #brief move constructor
*/
Circuits(Circuits&& c) noexcept
{
countIncrease();
}
/**
* @brief copy assignment operator
*/
Circuits& operator=(const Circuits& c)
{
if (this != &c)
{
countIncrease();
}
return *this;
}
static void show_objectCount() { std::cout << "\n circuits object count: "
<< circuits_objectCount << std::endl; }
static int get_objectCount() { return circuits_objectCount; }
constexpr void setCircuitVal(long double val) {}
/**
* @brief Calculates the total resistance of a series of resistors.
* @param R The array of resistors.
* @param print Whether to print the results.
* @return The total resistance in ohms.
*/
static long double seriesResistance(
const vector<long double>& R, bool print);
/**
* @brief Calculates the total resistance of resistors hooked up in parallel.
* @param R The array of resistors.
* @param print Whether or not to print the results.
* @return The total resistance in ohms.
*/
static long double parallelResistance(
const vector<long double>& R, bool print);
/**
* @brief Calculates the total capacitance_Qv of capacitors hooked up in parallel.
* ┌───┴───┐
* ┴ ┴ => ┴ c = c1 + c2 + ... + cn
* C1 ┬ ┬ C2 ┬
* └───┬───┘
* @param C The array of capacitors.
* @param print Whether or not to print the results.
* @return The total capacitance_Qv (F).
*/
static long double parallelCapacitance(
const vector<long double>& C, bool print);
/**
* @brief Calculates the total capacitor of a series of capacitors.
* ┴
* C1 ┬
* ┴ => ┴ c = 1 / (1/c1 + 1/c2 + ... + 1/cn)
* C2 ┬ ┬
*
* @param C The array of capacitors.
* @param print Whether or not to print the results.
* @return The total capacitance_Qv (F).
*/
static long double seriesCapacitance(
const vector<long double>& C, bool print);
/**
* @brief Calculates the terminal voltage.
* @param emf The electromotive force.
* @param r The internal resistance.
* @param I The charge.
* @param print Whether or not to print the results.
* @return The voltage.
*/
static constexpr long double terminalVoltage(
long double emf, long double r, long double I, bool print = true);
/**
* @brief Calculates the current of a circuit using Ohm's law.
* @param emf The electromotive force.
* @param RLoad The resistance load of all resistors connected.
* @param r The internal resistance.
* @param print Whether or not to print the results.
* @return The current (A).
*/
static constexpr long double current_emfRloadr(
long double emf, long double RLoad, long double r, bool print = true);
/**
* @brief Calculates the powers dissipated.
* @param I The current.
* @param R The resistance.
* @param print Whether or not to print the results.
* @return The power dissipated in watts (W).
*/
static constexpr long double powerDissipation_IR(
long double I, long double R, bool print = true);
/**
* @breif Calculates the power dissipated in a resistor, when the current
* is I and the voltage is V.
* @param I The current.
* @param V The voltage.
* @param print Whether or not to print the results.
* @return The power dissipated in watts (W).
*/
static constexpr long double powerDissipation_IV(
long double I, long double V, bool print = true);
/**
* @brief Calculates the power dissipated in a resistor, when the voltage
* is V and the resistance is R.
* @param V The voltage.
* @param R The resistance.
* @param print Whether or not to print the results.
* @return The power dissipated in watts (W).
*/
static constexpr long double powerDissipation_VR(
long double V, long double R, bool print = true);
/**
* @brief Calculates the power dissipated in a resistor, when the battery
* has an emf of E and the internal resistance is r and is connected to a
* resistor with resistance R.
* @param E The electromotive force.
* @param R The resistance.
* @param r The internal resistance.
*/
static long double powerDissipation_ErR(
long double E, long double R, long double r, bool print = true);
/**
* @brief Calculates the total power dissipated by a series of resistors,
* given a battery with an emf of E and an internal resistance of r.
* @param E The electromotive force.
* @param R The array of resistors.
* @param r The internal resistance.
* @param print Whether or not to print the results.
* @return The total power output in watts (W).
*/
static long double powerDissipation_series(
long double E, const vector<long double>& R, long double r,
bool print = true);
/**
* @brief Calulates the total power dissipated by a series of resistors,
* given a battery with voltage V V.
* @param V The voltage.
* @param R The array of resistors.
* @param print Whether or not to print the results.
* @return The total power output in watts (W).
*/
static long double powerDissipation_series_VR(
long double V, const vector<long double>& R, bool print = true);
/**
* @brief Calculates the total power dissipated by a circuit of resistors
* in parallel, given a battery with an emf of E and an internal resistance
* of r.
* @param E The electromotive force.
* @param R The array of resistors.
* @param r The internal resistance.
*/
static long double powerDissipation_parallel(
long double E, const vector<long double>& R, long double r,
bool print = true);
/**
* @brief Calculates the total power dissipated by a circuit of resistors
* in parallel, given a battery with voltage V.
* @param V The voltage.
* @param R The array of resistors.
* @param print Whether or not to print the results.
* @return The total power output in watts (W).
*/
static long double powerDissipation_parallel_VR(
long double V, const vector<long double>& R, bool print = true);
/**
* @brief adds the total emfs for a series connection. where emf is the
* electromagnetic force
* @param emfs The emfs.
* @param print Whether or not to print the results.
* @return net emf
*/
static long double emfsParallelConnection_added(
const vector<ld>& emfs, bool print = true);
/**
* @brief subtracts the total emfs for a series connection. where emf is the
* electromagnetic force
* @param emfs The emfs.
* @param print Whether or not to print the results.
* @return net emf
*/
static long double emfsSeriesConnection_subtracted(
vector<ld> emfs, bool print = true);
/**
* @brief Calculates the internal resistance.
* @param Vt The terminal voltage.
* @param E The emf.
* @param I The current.
* @param print Whether or not to print the results.
* @return The internal resistance (r).
*/
static constexpr long double internalResistance(
long double Vt, long double E, long double I, bool print = true);
/**
* @brief Calculates the RC time constant of a circuit containing a resistor
* and a capacitor.
* @param R The resistance.
* @param C The capacitance_Qv.
* @param print Whether or not to print the results.
* @return tau (Greek letter)
*/
static constexpr long double timeConstant_RC(
long double R, long double C, bool print = true);
/**
* @brief Calculates the resistance from the time constant and capacitance_Qv.
* @param tau The time constant.
* @param C The capacitance_Qv.
* @param print Whether or not to print the results.
* @return The resistance (Ohms).
*/
static constexpr long double resistance_fromTimeConstant(
long double tau, long double C, bool print = true);
/**
* @brief Calculates the capacitance_Qv from time constant and resistance.
* @param tau The time constant.
* @param R The resistance.
* @param print Whether or not to print the results.
* @return The capacitance_Qv (F).
*/
static constexpr long double capacitance_fromTimeConstant(
long double tau, long double R, bool print = true);
/**
* @brief Calculates the voltage across a capacitor as it charges.
* @param emf The electromotive force.
* @param t The time.
* @param R The resistance.
* @param C The capacitance.
* @param print Whether or not to print the results.
* @return The voltage (V).
*/
static long double voltageRCCircuitCharging(
long double emf, long double t, long double R, long double C, bool print = true);
/**
* @brief Calculates the voltage across a capacitor as it discharges.
* @param V_0 The initial voltage.
* @param t The time.
* @param R The resistance.
* @param C The capacitance.
*/
static long double voltageRCCircuitDischarging(
long double V_0, long double t, long double R, long double C, bool print = true);
/**
* @brief Calculate the current in an RC circuit as it charges.
* @param emf The electromotive force.
* @param t The time.
* @param R The resistance.
* @param C The capacitance.
* @param print Whether or not to print the results.
* @return The current (A).
*/
static long double currentRCCircuitCharging(
long double emf, long double t, long double R, long double C, bool print = true);
/**
* @brief Calculate the current in an RC circuit as it discharges.
* @param V_0 The initial voltage.
* @param t The time.
* @param R The resistance.
* @param C The capacitance.
* @param print Whether or not to print the results.
* @return The current (A).
*/
static long double currentRCCircuitDischarging(
long double V_0, long double t, long double R, long double C, bool print = true);
/**
* @brief Calculate the current (I_0) that flows through a resistor with R Ohms
* resistance immediately after a switch is throw, when there is a capacitor in
* series with the resistor and has a capacitance of C F and has an
* initial charge of q.
* @param R The resistance.
* @param C The capacitance.
* @param q The initial charge.
* @param print Whether or not to print the results.
* @return The current (A).
*/
static long double current_RCq(
long double R, long double C, long double q, bool print = true);
/**
* @brief Calculates the frequency from cycles and seconds.
* @param cycles The cycles.
* @param seconds The seconds.
* @param print Whether or not to print the results.
* @return The frequency (Hz).
*/
static constexpr long double frequency(
long double cycles, long double seconds, bool print = true);
/**
* @brief Calculates the frequency from the period.
* @param period The period.
* @param print Whether or not to print the results.
* @return The frequency (Hz).
*/
static constexpr long double frequency(long double period, bool print = true);
/**
* @brief Calculates the angular frequency of an AC current (omega) from the
* frequency of the current (f).
* @param f The frequency.
* @param print Whether or not to print the results.
* @return The frequency (Hz).
*/
static constexpr long double angularFrequency(long double f, bool print = true);
/**
* @brief Calculates the resonant frequency of at which an LC circuit
* oscillates.
* @param L The inductance.
* @param C The capacitance.
* @param print Whether or not to print the results.
* @return The angular frequency (rad/s).
*/
static constexpr long double resonantFrequency(
long double L, long double C, bool print = true);
/**
* @brief Calculates the period from the frequency.
* @param f The frequency.
* @param print Whether or not to print the results.
* @return The period (s).
*/
static constexpr long double period(long double f, bool print = true);
/**
* @brief Calculates the resistance from DC equations.
* @param t The time.
* @param VoverE The V/E .
* @param C The capacitance_Qv.
* @param print Whether or not to print the results.
* @return The resistance (Ohms).
*/
static long double resistance_fromDCequations(
long double t, long double VoverE, long double C, bool print = true);
/**
* @brief calculates using the exact exponential treatment, how much time is
* required to discharge a C F capacitor through a R Ω resistor down to pOv%
* of its original voltage.
* @param C The capacitance_Qv.
* @param R The resistance.
* @param pOv The percent of original voltage.
* @param print Whether or not to print the results.
* @return time in seconds
*/
static long double time_fromDischargeEquation(
long double C, long double R, long double pOv, bool print = true);
/**
* @brief A camera flash gets its energy from a C F capacitor and requires
* V volts to fire. If the capacitor is charged by a emf-V source through
* an resistor of R ohms, calculate how long the photographer must wait
* between flashes. Assume the capacitor is fully discharged with each flash.
* @param C The capacitance.
* @param V The voltage.
* @param emf The electromotive force.
* @param R The resistance.
* @param print Whether or not to print the results.
* @return The time (s).
*/
static long double time_fromCameraFlash(
long double C, long double V, long double emf, long double R, bool print = true);
/**
* @brief If you wish to take a picture of a bullet traveling at v m/s, then
* a very brief flash of light produced by an RC discharge through a flash
* tube can limit blurring. Assuming d m of motion during one RC constant
* is acceptable, and given that the flash is driven by a C F capacitor,
* what is the resistance in the flash tube?
* @param d The distance in meters.
* @param C The capacitance_Qv.
* @param v The velocity.
* @param print Whether or not to print the results.
* @return resistance in Ohms
*/
static constexpr long double resistance_fromDistanceVelocity(
long double d, long double C, long double v, bool print = true);
/**
* @brief A flashing lamp in a Christmas earring is based on an RC discharge
* of a capacitor through its resistance. The effective duration of the flash
* is t s, during which it produces an average 0.500 W from an average 3.00 V.
* calculates the energy it dissipates?
* @param P The power.
* @param t The time.
* @param print Whether or not to print the results.
* @return energy in joules
*/
static constexpr long double energyUsed(long double P, long double t, bool print = true);
/**
* @brief A flashing lamp in a Christmas earring is based on an RC discharge
* of a capacitor through its resistance. The effective duration of the flash
* is t s, during which it produces an average 0.500 W from an average 3.00 V.
* calculates the charge that moves through the lamp.
* @param P The power.
* @param V The volts.
* @param t The time.
* @param print Whether or not to print the results.
* @return coulombs
*/
static constexpr long double charge_fromPowerVoltsTime(
long double P, long double V, long double t, bool print = true);
/**
* @brief A C F capacitor charged to V is discharged through a resistor.
* Calculate the temperature increase of the resistor, given that its of a mass
* in kg and its specific heat is c kJ/kg⋅C∘, noting that most of the thermal
* energy is retained in the short time of the discharge.
* @param C The capacitance_Qv.
* @param V The volts.
* @param mass The mass.
* @param c The specific heat.
* @param print The print.
* @return temp in C
*/
static constexpr long double temperatureIncreaseOfResistor(
long double C, long double V, long double mass, long double c, bool print = true);
/// <summary>
/// EMFs the specified r.
/// </summary>
/// <param name="r">The r.</param>
/// <param name="R_load">The r load.</param>
/// <param name="I">The i.</param>
/// <returns></returns>
static constexpr long double emf(
long double r, long double R_load, long double I, bool print = true);
/**
* @brief Two oppositely charged but otherwise identical conducting plates
* of area A square meters are separated by a dielectric d meters thick,
* with a dielectric constant of K. The resultant electric field in the
* dielectric is E volts per meter. Calculate the results of the following:
* A) The magnitude of the charge per unit area σ on the conducting plate
* is in units C/m^2.
* B) The magnitude of the charge per unit area σ1 on the surfaces of the
* dielectric is in units C/m^2.
* C) The total electric-field energy U stored in the capacitor is in units J.
*
* @param A area of the plates
* @param d thickness of the dielectric
* @param K dielectric constant
* @param E electric field
* @param print print the results
* @return std::tuple<long double, long double, long double>
* (σ, σ1, U)
*/
static std::tuple<long double, long double, long double>
conductingPlatesChargeData(
long double A, long double d, long double k, long double E, bool
print = true);
/**
* @brief Consider two parallel-plate capacitors identical in shape, one
* is aligned so that the plates are horizontal, and the other
* with the plates vertical. The horizontal capacitor is filled halfway
* with a material that has an arbitrary dielectric constant K.
* What fraction f of the area of the vertical capacitor should be filled
* with the same dielectric so that the two capacitors have equal capacitance_Qv?
* Express your answer in terms of K.
* @param A area of the horizontal capacitor
* @param d thickness of the dielectric
* @param K dielectric constant
* @param print print the results
* @return long double f
*/
static long double fractionOfArea(
long double A, long double d, long double k, bool print = true);
/**
* @brief Calculate the dielectric constant of a capacitor with a capacitance_Qv
* of C F and a surface area of A m^2, and distance between plates of d m.
* @param C the capacitance_Qv (F)
* @param A the surface area (m^2)
* @param d the distance between the plates (m)
* @param print true to print the answer
* @return the dielectric constant
*/
static ld dielectricConstant(ld C, ld A, ld d, bool print = true);
/**
* @brief Calculate the charge stored on the positive plate of a capacitor
* with a capacitance_Qv of C F and a voltage of V volts.
* @param C the capacitance_Qv (F)
* @param V the voltage (V)
* @param print true to print the answer
* @return the charge (C)
*/
static ld chargeOnPositivePlate(ld C, ld V, bool print = true);
/**
* @brief Calculate the electric potential V(h) inside the capacitor as a
* function of height h. Take the potential at the bottom plate to be zero,
* and the electric field to be uniform inside the capacitor with a strength
* of E V/m.
* @param E the electric field strength (V/m)
* @param h the height (m)
* @param print true to print the answer
* @return the electric potential (V)
*/
static ld electricPotential(ld E, ld h, bool print = true);
/**
* @brief An electron of charge −qe (where qe is a positive
* quantity) is placed within the electric field at height h0, between the
* plates of a capacitor. Calculate the electon's potential energy U(h0),
* neglecting gravitational potential energy. Take the Electric field to be
* uniform inside the capacitor with a strength of E V/m.
* @param E the electric field strength (V/m)
* @param h0 the height (m)
* @param qe the charge (C)
* @param print true to print the answer
*/
static ld electronPotentialEnergy(ld E, ld h0, ld qe, bool print = true);
/**
* @brief An electron of mass m and charge −qe (where qe is a positive
* quantity) is placed within the electric field at height h0.
* The electron, having been held at height h0, is now released from rest.
* Calculate its speed v (i.e., |v⃗ |) when it reaches the top plate (height h1).
* Take the Electric field to be uniform inside the capacitor with a strength
* of E V/m.
* @param E the electric field strength (V/m)
* @param h0 the height (m)
* @param h1 the height (m)
* @param m the mass (kg)
* @param qe the charge (C)
* @param print true to print the answer
*/
static ld electronSpeed(ld E, ld h0, ld h1, ld m, ld qe, bool print = true);
/**
* @brief An uncharged capacitor has parallel plates l m on a side,
* spaced d m apart. Calculate how much charge must be transferred
* between the initially uncharged plates in order to store U J of energy?
* @param l the length (m)
* @param d the distance (m)
* @param U the energy (J)
* @param print true to print the answer
* @return the capacitance_Qv (F) and charge (C)
*/
static vector<ld> chargeToStoreEnergy(
ld l, ld d, ld U, bool print = true);
/**
*
* @brief Calculate the potential difference between the plates of a capacitor
* with a capacitance_Qv of C F and a charge of Q C.
* @param C the capacitance_Qv (F)
* @param Q the charge (C)
* @param print true to print the answer
* @return the potential difference (V)
*/
static ld potentialDifferenceBetweenPlates_CQ(
ld C, ld Q, bool print = true);
/**
* @brief Calculate the potential difference between two plates of a capacitor
* with an electric field of E V/m and a distance between the plates of d m.
* @param E the electric field (V/m)
* @param d the distance (m)
* @param print true to print the answer
* @return the potential difference (V)
*/
static ld potentialDifferenceBetweenPlates_Ed(
ld E, ld d, bool print = true);
/**
* @brief A capacitor of C F is hooked to a source with a voltage of V
* volts. Calculate how much energy is stored whehn the capacitor is
* is fully charged.
* @param C the capacitance_Qv (F)
* @param V the voltage (V)
* @param print true to print the answer
*/
static ld energyStoredInCapacitor_CV(ld C, ld V, bool print = true);
/**
* @brief calculate the energy stored in a capacitor with with a voltage
* of V and a charge of Q.
* @param V the voltage (V)
* @param Q the charge (C)
* @param print true to print the answer
*/
static ld energyStoredInCapacitor_VQ(ld V, ld Q, bool print = true);
/**
* @brief Calculate the energy stored in a capacitor with a capacitance_Qv
* of C and a charge of Q.
* @param C the capacitance_Qv (F)
* @param Q the charge (C)
* @param print true to print the answer
*/
static ld energyStoredInCapacitor_CQ(ld C, ld Q, bool print = true);
/**
* @brief Calculate the magnitude of the electric field E (V/m) between
* the plates of a capacitor with a charge density of sigma C/m^2.
* @param sigma the charge density (C/m^2)
* @param print true to print the answer
* @return the electric field (V/m)
*/
static ld electricFieldBetweenPlates(ld sigma, bool print = true);
/**
* @brief Calculate the magnitude of the electric field E (V/m) between
* the plates of a capacitor with a charge of Q C, and an area of A m^2.
* @param Q the charge (C)
* @param A the area (m^2)
* @param print true to print the answer
* @return the electric field (V/m)
*/
static ld electricFieldBetweenPlates_QA(ld Q, ld A, bool print = true);
/**
* @brief Calculate the magnitude of the force on a N ion with between the
* plates of a capacitor with an electric field of E V/m.
* @param E the electric field (V/m)
* @param N the charge (C)
* @param print true to print the answer
* @return the force (N)
*/
static ld forceOnIon(ld E, ld N, bool print = true);
/**
* @breif if released from the top plate of a capacitor, what would the
* kinetic energy of a charge of Q C be, giving a potential difference of V V?
* @param Q the charge (C)
* @param V the potential difference (V)
* @param print true to print the answer
* @return the kinetic energy (J)
*/
static ld kineticEnergyOfChargeBetweenPlates(ld Q, ld V, bool print = true);
/**
* @brief A spherical capacitor is formed from two concentric spherical
* conducting shells separated by vacuum. The inner sphere has a radius
* of ra m , and the outer sphere has a radius of rb m . A potential
* difference of V Volts is applied to the capacitor.
* Calculate the following:
* a) the capacitance_Qv of the capacitor.
* b) the magnitude E1 of the electric field E⃗ at
* radius r1 m , just outside the inner sphere.
* (Note: E⃗ is the electric field vector.)
* c) the magnitude of E⃗ at r2 m , just inside the outer sphere.
* @param ra the inner radius (m)
* @param rb the outer radius (m)
* @param V the potential difference (V)
* @param r1 the radius outside the inner sphere (m)
* @param r2 the radius just inside the outer sphere(m)
* @param print true to print the answer
* @return the capacitance_Qv (F), electric field (V/m) and electric field (V/m)
*/
static vector<ld> sphericalCapacitor(
ld ra, ld rb, ld V, ld r1, ld r2, bool print = true);
/**
* @brief Calculate the voltage V (V) across a capacitor in series, when
* the battery has a voltage of Vb (V).
* @param Vb the battery voltage (V)
* @param Capacitors the capacitances (F)
* @param print true to print the answer
* @return the voltages (V)
*/
static vector<ld> voltageAcrossEachCapacitorInSeries(
ld Vb, const vector<ld>& Capacitors, bool print = true);
/**
* @brief Calculate the Charge Q (C) on each capacitor in series, when
* the battery has a voltage of Vb (V).
* @param Vb the battery voltage (V)
* @param Capacitors the capacitances (F)
* @param print true to print the answer
* @return the charges (C)
*/
static vector<ld> chargeOnEachCapacitorInSeries(
ld Vb, const vector<ld>& Capacitors, bool print = true);
/**
* @brief Calculate the equivalent capacitance_Qv Ceq (F) of a circuit of capacitors
* that can be in series and in parallel. Use the isSeries flag to indicate
* whether the final calulation is in series or in parallel.
* @param series the capacitances in series (F)
* @param parallel the capacitances in parallel (F)
* @param isSeries true if the final calculation is in series
* @param print true to print the answer
* @return the equivalent capacitance_Qv (F)
*/
static ld equivalentCapacitance(
const vector<ld>& series, const vector<ld>& parallel,
bool isSeries = true, bool print = true);
/**
* @brief The energy density in a uniform electric field is U_e J/m^3
* Calculate the field strength.
* @param U_e the energy density (J/m^3)
* @param print true to print the answer
* @return the field strength (V/m)
*/
static ld fieldStrengthFromEnergyDensity(ld U_e, bool print = true);
/**
* @brief A medical defibrillator stores U J of energy in a C F
* capacitor. Calculate the following:
* a) The voltage across the capacitor?
* b) If the capacitor discharges U_dis J of its stored energy in t s,
* calculate the power delivered during this time.
*
* @param U the energy stored (J)
* @param C the capacitance_Qv (F)
* @param U_dis the energy discharged (J)
* @param t the time (s)
* @param print true to print the answer
* @return the voltage (V), power (W)
*/
static vector<ld> medicalDefibrillator(
ld U, ld C, ld U_dis, ld t, bool print = true);
/**
* @brief A capacitor consists of two long concentric metal cylinders.
* Calculate its capacitance_Qv in terms of the dimensions shown in the figure
* and constant ε0. Express your answer in terms of variables
* L, a, b, and constant ϵ0.
* @param L the length (m)
* @param a the inner radius (m)
* @param b the outer radius (m)
* @param print true to print the answer
* @return the capacitance_Qv (F)
*/
static ld concentricCylinders(ld L, ld a, ld b, bool print = true);
/**
* @brief An unknown capacitor C is connected in series with a C1s F
* capacitor, this pair is placed in parallel with a C1p F capacitor, and
* the entire combination is put in series with a Cfs F capacitor. When a
* potential difference of v V is applied across the open ends of this
* network, the total energy stored in all the capacitors is U J . Find C.
* @param C1s the capacitance_Qv of the first parallel capacitor (F)
* @param C1p the capacitance_Qv of the second series capacitor (F)
* @param Cfs the capacitance_Qv of the final series capacitor (F)
* @param v the potential difference (V)
* @param U the total energy stored (J)
* @param print true to print the answer
*/
static ld unknownCapacitor(
ld C1s, ld C1p, ld Cfs, ld v, ld U, bool print = true);
/**
* @brief An ion channel in a cell membrane carries I A when it's open,
* but it's open only y % of the time. Calculate what the average current
* is in the channel and if the channel opens for t s, calculate how many
* singly ionized atoms are transported through the channel.
* @param I the current (A)
* @param y the percentage open
* @param t the time (s)
* @param print true to print the answer
* @return the average current (A), the number of ions transported
*/
static vector<ld> ionChannel(ld I, ld y, ld t, bool print = true);
/**
* @brief A lightbulb with resistance Rl is designed to operate at a
* current of I A. To operate this lamp from a V-V battery, calculate the
* resistance you need to put in series with it.
* @param Rl the resistance of the lightbulb (Ω)
* @param I the current (A)
* @param V the voltage (V)
* @param print true to print the answer
* @return the resistance (Ω)
*/
static ld seriesResistance(ld Rl, ld I, ld V, bool print = true);
/**
* @brief Your car has a V-V battery with internal resistance Rint ohms.
* When the starter motor is cranking, it draws I A. Calculate the voltage
* across the battery terminals while starting.
* @param Rint the internal resistance (Ω)
* @param I the current (A)
* @param V the voltage (V)
* @param print true to print the answer
* @return the voltage (V)
*/
static ld voltageAcrossBattery(ld Rint, ld I, ld V, bool print = true);
/**
* @brief When a switch is open, a voltmeter of the battery reads Vo volts.
* When the switch is closed, the voltmeter reading drops to Vc
* volts, and the ammeter A reads I A . Assume that the two meters are
* ideal, so they do not affect the circuit. Calculate the resistance of
* the battery and the resistance of R.
* @param Vo the open voltage (V) (emf) (voltage across the battery)
* @param Vc the closed voltage (V) (Vt) (terminal voltage)
* @param I the current (A)
* @param print true to print the answer
* @return the emf (V)
*/
static vector<long double> internalExternalResistances(
ld Vopen, ld Vclosed, ld I, bool print = true);
/**
* @brief A V volts batter stores energy U J. Calculate how long it can
* light a flashlight buld that draws I A.
* @param V the voltage (V)
* @param U the energy stored (J)
* @param I the current (A)
* @param units the units to use:
* "s" for seconds, "m" for minutes, "h" for hours, "d" for days
* @param print true to print the answer
* @return the time
*/
static ld batteryLife_VUI(
ld V, ld U, ld I, char units = 's', bool print = true);
/**
* @brief There are n electrons inside a V V battery that produces I A
* of current. How long, in units, will the battery last?
* @param V the voltage (V)
* @param I the current (A)
* @param n the number of electrons
* @param units the units to use:
* "s" for seconds, "m" for minutes, "h" for hours, "d" for days
* "y" for years
* @param print true to print the answer
* @return the time
*/
static ld batteryLife_VIn(
ld V, ld I, ld n, char units = 's', bool print = true);
/**
* @brief Consider the junction of three wires as shown:
* W1 \ / W2
* \/
* |
* | W3
* The magnitudes of the current density for wire 1 and 2 are J1 A/m2
* and J2 A/m2, respectively, and the diameter of wires 1 and 2 are d1 m
* and d2 m, respectively. The current is flowing down W1 and up W2, and
* the direction of the current in W3 is unknown. Calculate the current
* I3 in W3 as well as calculate the magnitude of the current density in
* W3 given that it has a diameter of d3 m.
* @param J1 the current density of W1 (A/m2)
* @param J2 the current density of W2 (A/m2)
* @param d1 the diameter of W1 (m)
* @param d2 the diameter of W2 (m)
* @param d3 the diameter of W3 (m)
* @param print true to print the answer
* @return the current in W3 (A), the current density in W3 (A/m2)
*/
static vector<ld> currentDensityFromWireJunction(