-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMagnetism.h
More file actions
1719 lines (1564 loc) · 64 KB
/
Magnetism.h
File metadata and controls
1719 lines (1564 loc) · 64 KB
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/16/2021.
//
#ifndef PHYSICSFORMULA_MAGNETISM_H
#define PHYSICSFORMULA_MAGNETISM_H
/**
* @class Magnetism
* @details driver class for solving complex physics problems
* @author Ryan Zurrin
* @dateBuilt 3/18/2021
* @lastEdit 3/21/2021
*/
#include "ElectricCurrent.h"
#include "ElectricCharge.h"
static int magnetism_objectCount = 0;
// create an enum for all the different directions used in the right hand rule
enum class Direction
{
N, // North
S, // South
E, // East
W, // West
U, // up
D // down
};
typedef Direction dir;
// convert direction enum to string
static string dirToString(Direction dir)
{
switch (dir)
{
case dir::N:
return "North";
case dir::S:
return "South";
case dir::E:
return "East";
case dir::W:
return "West";
case dir::U:
return "Up or Into Page";
case dir::D:
return "Down or Out of Page";
default:
return "Invalid Direction";
}
}
static struct RHR
{
RHR() = default;
vector<Direction> FORCE = {
dir::N, dir::N, dir::N, dir::N,
dir::S, dir::S, dir::S, dir::S,
dir::E, dir::E, dir::E, dir::E,
dir::W, dir::W, dir::W, dir::W,
dir::U, dir::U, dir::U, dir::U,
dir::D, dir::D, dir::D, dir::D
};
vector<Direction> VELOCITY = {
dir::E, dir::W, dir::U, dir::D,
dir::E, dir::W, dir::U, dir::D,
dir::N, dir::S, dir::U, dir::D,
dir::N, dir::S, dir::U, dir::D,
dir::N, dir::S, dir::E, dir::W,
dir::N, dir::S, dir::E, dir::W
};
vector<Direction> B_FIELD = {
dir::U, dir::D, dir::W, dir::E,
dir::D, dir::U, dir::E, dir::W,
dir::D, dir::U, dir::N, dir::S,
dir::U, dir::D, dir::S, dir::N,
dir::E, dir::W, dir::S, dir::N,
dir::W, dir::E, dir::N, dir::S
};
// given force and velocity get the direction of the B field
basic_string<char> findBFieldDirection(Direction force, Direction velocity)
{
for (int i = 0; i < FORCE.size(); ++i)
{
if (FORCE[i] == force && VELOCITY[i] == velocity)
{
// return the direction of the B field as a string
return dirToString(B_FIELD[i]);
}
}
return "Invalid Direction";
}
// given force and B field get the direction of the velocity
basic_string<char> findVelocityDirection(Direction force, Direction BField)
{
for (int i = 0; i < FORCE.size(); ++i)
{
if (FORCE[i] == force && B_FIELD[i] == BField)
{
return dirToString(VELOCITY[i]);
}
}
return "Invalid Direction";
}
// given velocity and B field get the direction of the force
basic_string<char> findForceDirection(Direction velocity, Direction BField)
{
for (int i = 0; i < VELOCITY.size(); ++i)
{
if (VELOCITY[i] == velocity && B_FIELD[i] == BField)
{
return dirToString(FORCE[i]);
}
}
return "Invalid Direction";
}
}rhr;
static struct LHR
{
LHR() = default;
vector<Direction> FORCE = {
dir::N, dir::N, dir::N, dir::N,
dir::S, dir::S, dir::S, dir::S,
dir::E, dir::E, dir::E, dir::E,
dir::W, dir::W, dir::W, dir::W,
dir::U, dir::U, dir::U, dir::U,
dir::D, dir::D, dir::D, dir::D
};
vector<Direction> VELOCITY = {
dir::E, dir::W, dir::U, dir::D,
dir::E, dir::W, dir::U, dir::D,
dir::N, dir::S, dir::U, dir::D,
dir::N, dir::S, dir::U, dir::D,
dir::N, dir::S, dir::E, dir::W,
dir::N, dir::S, dir::E, dir::W
};
vector<Direction> B_FIELD = {
dir::D, dir::U, dir::E, dir::W,
dir::U, dir::D, dir::W, dir::E,
dir::U, dir::D, dir::S, dir::N,
dir::D, dir::U, dir::N, dir::S,
dir::W, dir::E, dir::N, dir::S,
dir::E, dir::W, dir::S, dir::N
};
// given force and velocity get the direction of the B field
basic_string<char> findBFieldDirection(Direction force, Direction velocity)
{
for (int i = 0; i < FORCE.size(); ++i)
{
if (FORCE[i] == force && VELOCITY[i] == velocity)
{
// return the direction of the B field as a string
return dirToString(B_FIELD[i]);
}
}
return "Invalid Direction";
}
// given force and B field get the direction of the velocity
basic_string<char> findVelocityDirection(Direction force, Direction BField)
{
for (int i = 0; i < FORCE.size(); ++i)
{
if (FORCE[i] == force && B_FIELD[i] == BField)
{
return dirToString(VELOCITY[i]);
}
}
return "Invalid Direction";
}
// given velocity and B field get the direction of the force
basic_string<char> findForceDirection(Direction velocity, Direction BField)
{
for (int i = 0; i < VELOCITY.size(); ++i)
{
if (VELOCITY[i] == velocity && B_FIELD[i] == BField)
{
return dirToString(FORCE[i]);
}
}
return "Invalid Direction";
}
}lhr;
class Magnetism :
public ElectricCurrent, public ElectricCharge
{
public:
Magnetism()
{
_magnetismVar = 0.0;
countIncrease();
}
explicit Magnetism(ld var)
{
_magnetismVar = 0.0;
countIncrease();
}
/**
* @brief copy constructor
*/
Magnetism(const Magnetism& t)
: ElectricCurrent(t), ElectricCharge(t) {
_magnetismVar = t._magnetismVar;
countIncrease();
}
/**
* #brief move constructor
*/
Magnetism(Magnetism&& t) noexcept
{
_magnetismVar = t._magnetismVar;
countIncrease();
}
/**
* @brief copy assignment operator
*/
Magnetism& operator=(const Magnetism& t)
{
if (this != &t)
{
_magnetismVar = t._magnetismVar;
countIncrease();
}
return *this;
}
void setMagnetismVar(ld var) { _magnetismVar = var; }
[[nodiscard]] ld getMagVar() const { return _magnetismVar; }
static void show_objectCount() { std::cout << "\n magnetism object count: "
<< magnetism_objectCount << std::endl; }
static int get_objectCount() { return magnetism_objectCount; }
/**
* @brief Calculates the m force (Lorentz force) on a charge q moving at
* a speed v in a m field of strength B where theta is the angle
* between the directions of v and B.
* @param q The charge in Coulombs.
* @param v The speed in m/s.
* @param B The m field strength.
* @param theta The angle theta between the directions
* @param print bool to print or not (default true)
* @return the m force in newtons
*/
static ld mForce(ld q, ld v, ld B, ld theta, bool print = true);
/**
* @brief Calculates the electrom force on a charge q moving at a speed v
* in a m field of strength with an electric field of strength E where
* theta is the angle between the directions of v and B.
* @param q The charge in Coulombs.
* @param v The speed in m/s.
* @param B The m field strength.
* @param E The electric field strength.
* @param theta The angle theta between the directions
* @param print bool to print or not (default true)
* @return the electrom force in newtons
*/
static ld electromForce(ld q, ld v, ld B, ld E, ld theta, bool print = true);
/**
* @brief Calculates the m force at a maximum angle of sin(90) which is 1.
* @param q The q.
* @param B The b.
* @param v The v.
* @param print bool to print or not (default true)
* @return m force (N)
*/
static ld mForceMax(ld q, ld B, ld v, bool print = true);
/**
* @brief Calculates the charge of a particle moving at right angles to the
* m field of B Tesla's with a speed of v m/s while experiencing a
* m force of F newtons.
* force of F Newtons.
* @param F The force.
* @param v The velocity.
* @param B The m field strength.
* @param print bool to print or not (default true)
* @return charge (C)
*/
static ld chargeOfParticle(ld F, ld v, ld B, bool print = true);
/**
* @brief A charged particle moving through a m field at an angles theta1 to
* the field with a speed of v1 m/s experiences a m force of
* F1 N. Determine the m force on an identical particle when
* it travels through the same m field with a speed of v2 m/s at
* an angle of theta2 relative to the m field.
* @param v1 The velocity of particle 1.
* @param v2 The velocity of particle 2.
* @param F1 The force on particle 1.
* @param theta1 The angle theta of particle 1.
* @param theta2 The angle theta of particle 2.
* @param print bool to print or not (default true)
* @return force on particle 2
*/
static ld mForceOnIdenticalParticle(ld v1, ld v2, ld F1, ld theta1, ld theta2, bool print = true);
/**
* @brief calculates the m the field strength.
* B = F/(q*v*sin(theta*RADIAN))
* @param F The m force (N).
* @param q The charge (C).
* @param v The speed (m/s).
* @param theta The angle theta.
* @param print bool to print or not (default true)
* @return Tesla(T)
*/
static ld mFieldStrength(
ld F, ld q, ld v, ld theta = 90.0, bool print = true);
/**
* @brief Calculates the m field strength from the centripetal motion of a
* particle moving on a curvature of radius of r with a of mass m at a speed
* of v with a charge of q .
* @param m The mass.
* @param v The speed.
* @param q The charge.
* @param r The radius.
* @param print bool to print or not (default true)
* @return Tesla's (T)
*/
static ld mFieldStrength_Fc(ld m, ld v, ld q, ld r, bool print = true);
/**
* @brief Calculates the m field strength of a straight current carrying wire.
* @param I The current.
* @param r The shortest distance to the wire.
* @param print bool to print or not (default true)
* @return magnitude of m field strength
*/
static ld mFieldStrength_straightCurrentCarryingWire(ld I, ld r, bool print = true);
/**
* @brief Calculates the m field strength center circular loop(s).
* @param I The current.
* @param R The radius of loop.
* @param N The number of loops, default is 1.
* @param print bool to print or not (default true)
* @return m field strength (T)
*/
static ld mFieldStrengthCenterCircularLoop(ld I, ld R, ld N, bool print = true);
/**
* @brief Calculates the m field strength inside solenoid.
* @param n The number of loops per unit length n = N/l.
* @param I The current.
* @param print bool to print or not (default true)
* @return m field strength inside a solenoid
*/
static ld mField_solenoid(ld n, ld I, bool print = true);
/**
* @brief Calculates the m field strength inside solenoid.
* @param N The Number of loops.
* @param l The length.
* @param I The current.
* @param print bool to print or not (default true)
* @return m field strength (T)
*/
static ld mField_solenoid(ld N, ld l, ld I, bool print = true);
/**
* @brief Calculate the turns per unit length of a solenoid from the wire
* diameter.
* @param d The diameter of the wire.
* @param print bool to print or not (default true)
*/
static ld turnsPerUnitLength(ld d, bool print = true);
/**
* @brief The solenoid used in an MRI scanner is l m long and d m in
* diameter. It’s wound from superconducting wire d_sc m in diameter, with
* adjacent turns separated by an insulating layer of negligible thickness.
* Find the current that will produce a B T m field inside the
* solenoid.
* @param d The diameter of the superconducting wire.
* @param B The m field strength.
* @param print bool to print or not (default true)
*/
static ld currentInSolenoid(ld d, ld B, bool print = true);
/**
* @brief Frustrated by the small Hall voltage obtained in blood flow measurements,
* a medical physicist decides to increase the applied m field strength
* to get a E(hall voltage) output for blood moving at v m/s in a d m-diameter
* vessel. Calculate the m field strength needed.
* @param E The hall voltage.
* @param d The diameter of vessel.
* @param v The speed.
* @param print bool to print or not (default true)
* @return the m field strength
*/
static ld mFieldStrengthHallVoltage(ld E, ld d, ld v, bool print = true);
/**
* @brief Loops per unit length.
* @param N The number of loops.
* @param l The length.
* @param print bool to print or not (default true)
* @return loops per unit length
*/
static ld loopsPerUnitLength(ld N, ld l, bool print = true);
/**
* @brief calculates the centripetal force.
* @param m The mass.
* @param v The velocity.
* @param r The radius.
* @param print bool to print or not (default true)
* @return centripetal force
*/
static ld centripetalForce(ld m, ld v, ld r, bool print = true);
/**
* @brief calculates the radius of the curvature of the path of a charged particle
* with a charge of q and a mass of m moving at a speed of v perpendicular
* to a m field of strength B
* @param m The mass.
* @param v The velocity.
* @param q The charge.
* @param B The m field strength.
* @param theta The angle theta, defaulted at 90.
* @param print bool to print or not (default true)
* @return radius in meters
*/
static ld radiusCurvatureOfPath(ld m, ld v, ld q, ld B, ld theta, bool print = true);
/**
* @brief If a single circular loop of wire carries a current of I A and produces
* a m field at its center with a magnitude of B T, determine
* the radius of the loop.
* @param I The current.
* @param B The m field strength.
* @param print bool to print or not (default true)
* @return radius of loop (m)
*/
static ld radiusLoopOfCurrentCarryingWire(ld I, ld B, bool print = true);
/**
* @brief The wire carrying I1 A to the motor of a commuter train feels an
* attractive force per unit length of Fl N/m due to a parallel
* wire carrying I2 A to a headlight. Calculate how far apart the two wires
* are.
* @param I1 The current first wire.
* @param I2 The current second wire.
* @param Fl The force per unit length.
* @param print bool to print or not (default true)
* @return distance between wires (m)
*/
static ld distanceBetween2wires(ld I1, ld I2, ld Fl, bool print = true);
/**
* @brief Two power lines run parallel for a distance of l m and are separated
* by a distance of r m. If the current in each of the two lines is I1 A and
* I2 A and if they run in opposite directions, determine the magnitude
* of the force each wire exerts on the other.
* @param I1 The current wire 1.
* @param I2 The current wire 2.
* @param l The length of wires.
* @param r The distance between the wires.
* @param print bool to print or not (default true)
* @return magnitude of force
*/
static ld forceMagnitude2wires(ld I1, ld I2, ld l, ld r, bool print = true);
/**
* @brief Calculates the mass of a charged particle of charge q moving in a
* curvature of radius r at a speed of v in a m field strength of B
* @param r The radius.
* @param q The charge.
* @param B The m field strength.
* @param v The velocity.
* @param print bool to print or not (default true)
* @return mass of particle in kg
*/
static ld massOfChargedParticle(ld r, ld q, ld B, ld v, bool print = true);
/**
* @brief Calculates the velocity of a charged particle moving on a curvature of
* radius r with a charge of q in a m field strength of B having a
* mass of m.
* @param r The radius.
* @param q The charge.
* @param B The m field strength.
* @param m The mass.
* @param print bool to print or not (default true)
* @return the speed of particle (m/s)
*/
static ld velocityOfChargedParticle(ld r, ld q, ld B, ld m, bool print = true);
/**
* @brief Calculates the Hall effect voltage (where B,v, and l are mutually
* perpendicular) across a conductor of width l, through which charges move
* at a speed of v through a uniform electric field.
* @param B The electric field strength.
* @param l The width.
* @param v The speed.
* @param print bool to print or not (default true)
* @return the hall emf (V)
*/
static ld hallEMF(ld B, ld l, ld v, bool print = true);
/**
* @brief Calculates the force on wire.
* @param n The number of charge carriers.
* @param q The charge of each carrier.
* @param A the cross sectional area.
* @param vD The drift velocity.
* @param l The length of wire.
* @param B The uniform m field strength.
* @param theta The angle theta between vD and B.
* @param print bool to print or not (default true)
* @return force in newtons
*/
static ld forceOnWire(ld n, ld q, ld A, ld vD, ld l, ld B, ld theta, bool print = true);
/**
* @brief Consider a wire of length L m that runs north-south on a horizontal
* surface. There is a current of I A flowing north in the wire.
* The Earth's magnetic field at this location has a magnitude of B gauss
* (or, in SI units, Tesla (T)) and points north and theta degrees down
* from the horizontal, toward the ground. Calculate what the size of
* the magnetic force on the wire due to the Earth's magnetic field is. In
* considering the agreement of units, recall that 1T=1N/(A⋅m)
* @param I The current.
* @param L The length of the wire.
* @param B The magnitude of the magnetic field.
* @param theta The angle between the magnetic field and the wire.
* @param print bool to print or not (default true)
* @return force (N)
*/
static ld forceOnWire(ld I, ld l, ld B, ld theta = 90.0, bool print = true);
/**
* @brief Calculates the force per unit length between two parallel wires.
* @param I1 The current 1.
* @param I2 The current 2.
* @param r The distance of separation.
* @param print bool to print or not (default true)
* @return N/m
*/
static ld forcePerUnitLengthBetween2ParallelWires(ld I1, ld I2, ld r, bool print = true);
/**
* @brief Two long straight current-carrying wires run parallel to each other.
* The current in one of the wires is I1 A, their separation is r (m)
* and they repel each other with a force per unit length of Fl N/m.
* @param I1 The known current.
* @param r The distance between wires.
* @param Fl The force per unit length.
* @param print bool to print or not (default true)
* @return unknown current in wire 2 (A)
*/
static ld currentFromWire2ParallelRunning(ld I1, ld r, ld Fl, bool print = true);
/**
* @brief Calculates the torque on a current carrying loop of uniform m
* field. Valid for a loop of any shape. The loop carries a current of I,
* and has N turns each of area A, and the perpendicular to the loop makes
* an angle theta with the m field B.
* @param N The number of loops.
* @param I The current (A).
* @param A The area (m^2).
* @param B The m field strength (T).
* @param theta The angle between the loop and the m
* field.
* @param print bool to print or not (default true)
* @return torque (N*m)
*/
static ld torqueOnCurrentCarryingLoop_umf(ld N, ld I, ld A, ld B, ld theta, bool print = true);
/**
* @brief Calculates the maximum torque on a current carrying loop of uniform m
* field. Valid for a loop of any shape. The loop carries a current of I,
* and has N turns each of area A, with a uniform m field B. The
* angle of sin at max torque is 90 degrees which sin(90) = 1 so sin is removed
* from this equation.
* @param N The number of loops.
* @param I The current (A).
* @param A The area (m^2).
* @param B The uniform m field strength (T).
* @param print bool to print or not (default true)
* @return torque (N*m)
*/
static ld torqueMaxOnCurrentCarryingLoop_umf(ld N, ld I, ld A, ld B, bool print = true);
/**
* @brief Calculates the current in a current carrying loop using known torque when
* at maximum with a N number of loops each with an area of A and a uniform
* m field strength of B.
* @param tMax The torque maximum.
* @param N The number of loops.
* @param A The area.
* @param B The m filed strength.
* @param print bool to print or not (default true)
* @return current in loops (A)
*/
static ld currentFromTorqueMax(ld tMax, ld N, ld A, ld B, bool print = true);
/**
* @brief Calculates the current in a long straight wire that would produce a
* m field of B at a distance of r (m) from the wire
* @param r The shortest distance to the wire.
* @param B The m field strength.
* @param print bool to print or not (default true)
* @return current (A)
*/
static ld currentInLongStraightWire(ld r, ld B, bool print = true);
/**
* @brief You have designed and constructed a solenoid to produce a m field
* equal in magnitude to B. If your solenoid
* has n turns and is l cm long, determine the current you must use in
* order to obtain a m field of the desired magnitude.
* @param B The desired m field strength.
* @param n The number of turns on the solenoid.
* @param l The length of the solenoid.
* @param print bool to print or not (default true)
* @return the current needed (I)
*/
static ld currentSolenoid(ld B, ld n, ld l, bool print = true);
/**
* @brief Calculate the angle the velocity of the electron
* makes with the m field if an electron moving at v m/s
* in a B (T) m field experiences a m force of F N.
* @param v The velocity.
* @param B The electric field strength.
* @param F The force.
* @param q The charge, default is elementary charge of electron.
* @param print bool to print or not (default true)
* @return angle theta
*/
static ld angleThetaOfElectronTomField(ld v, ld B, ld F, ld q, bool print = true);
/**
* @brief A velocity selector in a mass spectrometer uses a B(T) m field.
* Calculate what electric field strength is needed to select a
* speed of v m/s.
* @param v The velocity selected on the spectrometer.
* @param B The m field strength.
* @param theta The angle theta, default at sin(90) = 1.
* @param print bool to print or not (default true)
* @return electric field strength newton/coulombs (N/C)
*/
static ld electricFieldStrength_vB(ld v, ld B, ld theta, bool print = true);
/**
* @brief A mass spectrometer separates ions according to their ratio of
* charge to mass. Such devices are widely used in science and engineering
* to analyze unknown mixtures and to separate isotopes of chemical elements.
* Figure 26.7 shows ions of charge and mass first being accelerated from
* rest through a potential difference and then entering a region of uniform
* m field pointing out of the page. Only the m force acts on
* the ions in this region, so they undergo circular motion and, after half
* an orbit, land on a detector. Find an expression for the horizontal distance
* from the entrance slit to the point where an ion lands on the detector.
* @param q The charge of the ion.
* @param m The mass of the ion.
* @param V The potential difference.
* @param B The m field strength.
* @param print bool to print or not (default true)
* @return distance (m)
*/
static ld distanceIonLandsOnDetector(ld q, ld m, ld V, ld B, bool print = true);
/**
* @brief Calculate the cyclotron frequency of a particle with charge q and mass m
* in a m field B.
* @param q The charge of the particle.
* @param m The mass of the particle.
* @param B The m field strength.
* @param print bool to print or not (default true)
* @return frequency (Hz)
*/
static ld cyclotronFrequency(ld q, ld m, ld B, bool print = true);
/**
* @brief Calculate the period of a particles circular orbit in a m field B.
* @param q The charge of the particle.
* @param m The mass of the particle.
* @param B The m field strength.
* @param print bool to print or not (default true)
* @return period (s)
*/
static ld periodOfCircularOrbit(ld q, ld m, ld B, bool print = true);
/**
* @brief Calculate the m force on a current carrying wire in a
* m field B, where theta is the angle between the current and the
* m field.
* @param I The current.
* @param B The m field strength.
* @param l The length of current path.
* @param theta The angle between the current and the m field.
* Default is sin(90) = 1.
* @param print bool to print or not (default true)
* @return force (N)
*/
static ld mForceOnCurrentCarryingWire(
ld I, ld B, ld l, ld theta = 90.0, bool print = true);
/**
* @brief Calculate the charge using the biot-savart law.
* @param I The current.
* @param l The length of current path.
* @param r The distance from the current path to the point of interest.
* @param theta The angle between the current and the m field.
* Default is sin(90) = 1.
* @param print bool to print or not (default true)
*/
static ld biotSavartLaw(ld I, ld l, ld r, ld theta = 90.0, bool print = true);
/**
* @brief Calculating the m field at P due to an infinite straight
* wire carrying current along the axis.
* @param I The current.
* @param r The distance from the current path to the point of interest.
* @param print bool to print or not (default true)
*/
static ld mFieldStraightWire(ld I, ld r, bool print = true);
/**
* @brief Calculate the m force between two parallel wires.
* @param I1 The current in wire 1.
* @param I2 The current in wire 2.
* @param d The distance between the wires.
* @param l The length of the wires.
* @param print bool to print or not (default true)
* @return force (N)
*/
static ld mForceBetweenTwoParallelWires(
ld I1, ld I2, ld d, ld l, bool print = true);
/**
* @brief Use Ampere's law for steady currents to calculate the m field
* @param I The current.
* @param print bool to print or not (default true)
* @return m field (T)
*/
static ld amperesLaw(ld I, bool print = true);
/**
* @brief Ampère’s Law: Solar Currents The long dimension of a rectangular
* loop is l m, and the m field strength near the loop has a
* constant magnitude of B T. Estimate the total current encircled by
* the rectangle.
* @param l The length of the rectangle.
* @param B The m field strength.
* @param print bool to print or not (default true)
* @return current (A)
*/
static ld amperesLawSolarCurrents(ld l, ld B, bool print = true);
/**
* @brief Calculate the field outside andy current distribution with line
* symmetry.
* @param I The current.
* @param r The distance from the current path to the point of interest.
* @param print bool to print or not (default true)
* @return m field (T)
*/
static ld mField_lineCurrent_outside(ld I, ld r, bool print = true);
/**
* @brief Calculate the m field inside a uniform current
* distribution with line symmetry.
* @param I The current.
* @param r The distance from the current path to the point of interest.
* @param R The radius of the current distribution.
* @param print bool to print or not (default true)
* @return m field (T)
*/
static ld mField_lineCurrent_inside(ld I, ld r, ld R, bool print = true);
/**
* @brief Calculate the m field of an infinite width current sheet
* @param I The current.
* @param l The length of the current sheet.
* @param print bool to print or not (default true)
*/
static ld mField_sheet(ld I, ld l, bool print = true);
/**
* @brief Calculate the m dipole moment of a current loop.
* @param I The current.
* @param A The area of the current loop.
* @param print bool to print or not (default true)
* @return m dipole moment (A m^2)
*/
static ld mDipoleMoment_loop(ld I, ld A, bool print = true);
/**
* @brief find direction of Force using RHR given direction of velocity
* and the B field
* @param v Direction of velocity
* @param B Direction of B field
* @param positive bool, true if positive, false if negative (default true)
* @param print bool to print or not (default true)
* @return direction of force
*/
static basic_string<char> findDirectionOfForce(
Direction v, Direction B, bool positive = true, bool print = true);
/**
* @brief find the direction of velocity using RHR given direction of force
* and the B field
* @param F Direction of force
* @param B Direction of B field
* @param positive bool, true if positive, false if negative (default true)
* @param print bool to print or not (default true)
* @return direction of velocity
*/
static basic_string<char> findDirectionOfVelocity(
Direction F, Direction B, bool positive = true, bool print = true);
/**
* @brief find the direction of B field using RHR given direction of force
* and the velocity
* @param F Direction of force
* @param v Direction of velocity
* @param positive bool, true if positive, false if negative (default true)
* @param print bool to print or not (default true)
* @return direction of B field
*/
static basic_string<char> findDirectionOfBField(
Direction F, Direction v, bool positive = true, bool print = true);
/**
* @brief Calculate the net current through an Amperean loop with n
* loops and a current of I and length l.
* @param I The current.
* @param n The number of loops.
* @param l The length of the loops.
* @param print bool to print or not (default true)
* @return current (A)
*/
static ld netCurrentAmpereanLoop(ld I, ld n, ld l, bool print = true);
/**
* @brief Find B_in , the z component of the magnetic field inside the
* solenoid where Ampère's law applies.
* @param I The current.
* @param n The number of loops.
* @param l The length of the loops.
* @param print bool to print or not (default true)
*/
static ld B_in(ld I, ld n, ld l, bool print = true);
/**
* @brief A particle with positive charge q is moving with speed v along
* the z axis toward positive z. At the time of this problem it is located
* at the origin, x=y=z=0. Your task is to find the magnetic field at various
* locations in the three-dimensional space around the moving charge.
* Calculate the magnetic field at the point r⃗ due to the moving charge.
* @param q The charge.
* @param v The velocity.
* @param v_hat The direction of the velocity.
* @param r The distance from the charge.
* @param r_hat The direction of the distance from the charge.
* @param print bool to print or not (default true)
* @return m field (T)
*/
static ld mField_movingCharge(
ld q, ld v, Direction v_hat, ld r, Direction r_hat, bool print = true);
/**
* @brief J. J. Thomson is best known for his discoveries about the nature of
* cathode rays. Another important contribution of his was the invention,
* together with one of his students, of the mass spectrometer. The ratio of
* mass m to (positive) charge q of an ion may be accurately determined in a
* mass spectrometer. In essence, the spectrometer consists of two regions:
* one that accelerates the ion through a potential difference V and a second
* that measures its radius of curvature in a perpendicular magnetic field.
*
* The ion begins at potential V and is accelerated toward zero potential.
* When the particle exits the region with the electric field it will have
* obtained a speed u.
*
* Calculate what speed u does the ion exit the acceleration region.
* @param q The charge.
* @param V The potential difference.
* @param print bool to print or not (default true)
* @return speed (m/s)
*/
static ld speedOfIon(ld q, ld V, bool print = true);
/**
* @brief A wire carries I A. You form it into a single-turn circular loop
* and measure a magnetic field of B T at the loop center. Calculate the
* field strength on the loop axis at x m from the loop center.
* @param I The current.
* @param B The magnetic field.
* @param x The distance from the loop center.
* @param print bool to print or not (default true)
* @return field strength (T)
*/
static ld fieldStrengthOnLoopAxisAtX(ld I, ld B, ld x, bool print = true);
/**
* @brief A wire carries I A. You form it into a single-turn circular loop
* of radius r. Calculate the field strength on the loop axis at x m from
* the loop center.
* @param I The current.
* @param r The radius of the loop.
* @param x The distance from the loop center.
* @param print bool to print or not (default true)
* @return field strength (T)
*/
static ld fieldStrengthOnLoopAxisAtX_Irx(
ld I, ld r, ld x, bool print = true);
/**
* @brief A wire carrying I A makes a theta degrees angle with a uniform
* magnetic field. The magnetic force per unit length (F/l) of wire is
* fl N/m. Calculate the magnetic field strength.
* @param I The current.
* @param theta The angle.
* @param fl The magnetic force per unit length.
* @param print bool to print or not (default true)
* @return field strength (T)
*/
static ld mFieldStrength_Ithetafl(
ld I, ld theta, ld fl, bool print = true);
/**
* @brief A coil with magnetic moment mu A⋅m2 is oriented initially with
* its magnetic moment at theta_i to a uniform magnetic field of
* magnitude B T. Calculate the change in potential energy of the coil
* when it is rotated theta_f degrees.
* @param mu The magnetic moment.
* @param B The magnetic field.
* @param theta_i The initial angle.
* @param theta_f The final angle.
* @param print bool to print or not (default true)
* @return change in potential energy (J)
*/
static ld changeInPotentialEnergy_Mtheta_i_f(
ld mu, ld B, ld theta_i, ld theta_f, bool print = true);
/**
* @brief Consider a current I that flows in a plane rectangular current
* loop with height a m and horizontal sides b m. The loop is placed into
* a uniform magnetic field B in such a way that the sides of length a
* are perpendicular to B , and there is an angle theta between the sides
* of length b and B. Assume that the loop is initially positioned at
* theta_i degrees and the current flowing into the loop is I A. If the
* magnitude of the magnetic field is B, calculate what τ, the net torque
* about the vertical axis of the current loop due to the interaction of
* the current with the magnetic field.
* @param I The current.
* @param a The height of the loop.
* @param b The horizontal sides of the loop.
* @param B The magnetic field.
* @param theta_i The angle.
* @param theta_f The initial angle.
* @param print bool to print or not (default true)
*/
static ld netTorque_IabBtheta_theta_i(
ld I, ld B, ld a, ld b, ld theta_i, ld theta_f, bool print = true);
/**
* @brief a coaxial cable, widely used in electronics to minimize interference
* either with or from signals carried on the cable. The cable consists of
* an inner solid conductor of radius a and a hollow outer conductor of inner
* radius b and thickness c. The two conductors carry equal but opposite
* currents I, distributed uniformly over their cross-sectional areas.
* Calculate the magnetic field strength as a function of radial position
* r within the inner conductor.
* @warning B(0 ≤ r ≤ a)
* @param I The current.
* @param a The radius of the inner conductor.
* @param r The radial position.
* @param print bool to print or not (default true)
* @return field strength (T)
*/
static ld mFieldStrengthCoaxialCable_Iar(ld I, ld a, ld r, bool print =
true);
/**
* @brief a coaxial cable, widely used in electronics to minimize interference
* either with or from signals carried on the cable. The cable consists of
* an inner solid conductor of radius a and a hollow outer conductor of inner
* radius b and thickness c. The two conductors carry equal but opposite
* currents I, distributed uniformly over their cross-sectional areas.
* Calculate the magnetic field strength as a function of radial position
* r between the inner and outer conductors.
* @warning B(a ≤ r ≤ b)
* @param I The current.
* @param r The radial position.
* @param print bool to print or not (default true)