'''
Created on 01-Apr-2021
@author: rishi_priyansh
'''
import random
import inspect
import traceback
from sympy import (symbols, Symbol)

from xv.km.util import latex_fraction, latex_atom
from .....helper import BaseHelper

from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate
        
class MaxwellsEquationManager(BaseManager):
    '''
    MaxwellsEquationManager
    Example:
        ke = MaxwellsEquationManager()
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ...
        
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()
        
        ke.printProblemTypes()
        
    '''    
    _OPR_TYPE_COUNT = 10
    
    def __new__(cls, *args, **kwargs):
        instance = super(MaxwellsEquationManager, cls).__new__(cls, *args, **kwargs)
        for base_class in MaxwellsEquationManager.__bases__:
            base_class.__init__(instance, *args, **kwargs)
        return instance
    
    def __init__(self, *args, **kwargs):
        pass



    def _init_problem_types(self, *args, **kwargs):
        self._append_problem_types([
            '_derive_gauss_law_of_electric_field',
            '_derive_gauss_law_of_magnetic_field',
            '_derive_gauss_law_of_gravitational_field',
            '_derive_electric_field_of_point_charge',
            '_derive_electric_field_of_line_charge',
            '_derive_electric_field_of_plane_charge',
            '_problem_3_288',
            '_problem_3_289',
            '_problem_3_290',
            '_problem_3_291',
            '_problem_3_292',
            '_problem_3_293',
            '_problem_3_294',
            '_problem_3_295',
            '_problem_3_296',
            '_problem_3_297',
            
            ])
        pass
    
    def _derive_gauss_law_of_electric_field(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        Derive Gauss's law of electric field.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        The Gauss's law 
        <div style = "position: absolute; left: 0px; ">$$\oint_{{S}} \vec{{E}} \cdot \vec{{dA}}$$</div> <div style = "display: block; float: right;">$\vec{{E}}$ = The electric field of point charge
        $\vec{{dA}}$ = Closed area around the charge</div>
        <br/>
        <div style = "position: absolute; left: 0px; ">$$= \oint_{{S}} \frac{{1}}{{4\pi\epsilon_0}} \frac{{q}}{{r^2}} \widehat{{r}} \cdot \vec{{dA}}$$</div> <div style = "display: block; float: right;">$$\vec{{E}} = \frac{{1}}{{4\pi\epsilon_0}} \frac{{q}}{{r^2}} \widehat{{r}}$$
        $\epsilon_0$ = permittivity of vacuum
        $q$ = point charge
        $r$ = distance between point and charge</div>
        
        As the direction of the radius vector $\widehat{{r}}$ and $\vec{{dA}}$ are same. 
        <div style = "position: absolute; left: 0px; ">$$= \oint_{{S}} \frac{{1}}{{4\pi\epsilon_0}} \frac{{q}}{{r^2}} 1 dA \cos\left ( 0 \right )$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= \oint_{{S}} \frac{{1}}{{4\pi\epsilon_0}} \frac{{q}}{{r^2}} dA$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= \frac{{1}}{{4\pi\epsilon_0}} \frac{{q}}{{r^2}} \oint_{{S}} dA$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= \frac{{1}}{{4\pi\epsilon_0}} \frac{{q}}{{r^2}} A $$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= \frac{{1}}{{4\pi\epsilon_0}} \frac{{q}}{{r^2}} 4\pi r^2$$</div><div style = "display: block; float: right;">$$A = 4\pi r^2$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= \frac{{q}}{{\epsilon_0}}$$</div>
        
        The Gauss's law for electric field
        <div style = "position: absolute; left: 0px; ">$$\oint_{{S}} \vec{{E}} \cdot \vec{{dA}} = \frac{{q}}{{\epsilon_0}}$$</div>
        
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = soln_s
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _derive_gauss_law_of_magnetic_field(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        Derive Gauss's law of magnetic field.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        The Gauss's law 
        <div style = "position: absolute; left: 0px; ">$$\oint_{{S}} \vec{{B}} \cdot \vec{{dA}}$$</div> <div style = "display: block; float: right;">$\vec{{B}}$ = The magnetic field of point charge
        $\vec{{dA}}$ = Closed area around the charge</div>
        <br/>
        <div style = "position: absolute; left: 0px; ">$$= \oint_{{S}} \frac{{\mu_0}}{{4\pi}} \frac{{m}}{{r^2}} \widehat{{r}} \cdot \vec{{dA}}$$</div> <div style = "display: block; float: right;">$$\vec{{B}} = \frac{{\mu_0}}{{4\pi}} \frac{{m}}{{r^2}} \widehat{{r}}$$
        $\mu_0$ = Vacuum permeability
        $m$ = magnetic pole
        $r$ = distance between point and charge</div>
        
        
        As the direction of the radius vector $\widehat{{r}}$ and $\vec{{dA}}$ are same. 
        <div style = "position: absolute; left: 0px; ">$$= \oint_{{S}} \frac{{\mu_0}}{{4\pi}} \frac{{m}}{{r^2}} 1 dA \cos\left ( 0 \right )$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= \oint_{{S}} \frac{{\mu_0}}{{4\pi}} \frac{{m}}{{r^2}} dA$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= \frac{{\mu_0}}{{4\pi}} \frac{{m}}{{r^2}} \oint_{{S}} dA$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= \frac{{\mu_0}}{{4\pi}} \frac{{m}}{{r^2}} A $$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= \frac{{\mu_0}}{{4\pi}} \frac{{m}}{{r^2}} 4\pi r^2$$</div><div style = "display: block; float: right;">$$A = 4\pi r^2$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= \mu_0 m$$</div>
        
        The Gauss's law for magnetic field
        <div style = "position: absolute; left: 0px; ">$$\oint_{{S}} \vec{{B}} \cdot \vec{{dA}} = \mu_0 m$$</div>
        
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = soln_s
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _derive_gauss_law_of_gravitational_field(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        Derive Gauss's law of gravitational field.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        The Gauss's law 
        <div style = "position: absolute; left: 0px; ">$$\oint_{{S}} \vec{{E_G}} \cdot \vec{{dA}}$$</div> <div style = "display: block; float: right;">$\vec{{E_G}}$ = The gravitational field of point mass
        $\vec{{dA}}$ = Closed area around the charge</div>
        <br/>
        <div style = "position: absolute; left: 0px; ">$$= \oint_{{S}} G \frac{{m}}{{r^2}} \widehat{{r}} \cdot \vec{{dA}}$$</div> <div style = "display: block; float: right;">$$\vec{{E_G}} = G \frac{{m}}{{r^2}} \widehat{{r}}$$
        $G$ = gravitational constant
        $m$ = point mass
        $r$ = distance between point and charge</div>
        
        As the direction of the radius vector $\widehat{{r}}$ and $\vec{{dA}}$ are same. 
        <div style = "position: absolute; left: 0px; ">$$= \oint_{{S}} G \frac{{m}}{{r^2}} 1 dA \cos\left ( 0 \right )$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= \oint_{{S}} G \frac{{m}}{{r^2}} dA$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= G \frac{{m}}{{r^2}} \oint_{{S}} dA$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= G \frac{{m}}{{r^2}} A $$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= G \frac{{m}}{{r^2}} 4\pi r^2$$</div><div style = "display: block; float: right;">$$A = 4\pi r^2$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$= 4\pi G m$$</div>
        
        The Gauss's law for gravitational field
        <div style = "position: absolute; left: 0px; ">$$\oint_{{S}} \vec{{E_G}} \cdot \vec{{dA}} = 4\pi G m$$</div>
        
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = soln_s
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _derive_electric_field_of_point_charge(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        Derive electric field of a point charge with Gauss's law.

        <div style = "position: absolute; left: 0px; ">$$\oint_{{S}} \vec{{E}} \cdot \vec{{dA}} = \frac{{q}}{{\epsilon_0}}$$</div>
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        The Gauss's law 
        <div style = "position: absolute; left: 0px; ">$$\oint_{{S}} \vec{{E}} \cdot \vec{{dA}} = \frac{{q}}{{\epsilon_0}}$$</div> <div style = "display: block; float: right;">$\vec{{E}}$ = The electric field of point charge
        $\vec{{dA}}$ = Closed area around the charge
        $q$ = point charge
        $\epsilon_0$ = permittivity of vacuum</div>
        
        As the direction of the radius vector $\vec{{E}}$ and $\vec{{dA}}$ are same. 
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow \oint_{{S}} E dA \cos\left ( 0 \right ) = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow \oint_{{S}} E dA = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E \oint_{{S}} dA = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E \left [ A \right ]_{{S}} = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E A = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E 4\pi r^2 = \frac{{q}}{{\epsilon_0}}$$</div> <div style = "display: block; float: right;">$$A = 4\pi r^2$$
        $r$ = distance between point and charge</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E = \frac{{1}}{{4\pi r^2}} \frac{{q}}{{\epsilon_0}}$$</div>
        
        The electric field of a point charge
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E = \frac{{1}}{{4\pi \epsilon_0}} \frac{{q}}{{r^2}}$$</div>
        
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = soln_s
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _derive_electric_field_of_line_charge(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        Derive electric field of a line charge with Gauss's law.

        <div style = "position: absolute; left: 0px; ">$$\oint_{{S}} \vec{{E}} \cdot \vec{{dA}} = \frac{{q}}{{\epsilon_0}}$$</div>
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        The Gauss's law 
        <div style = "position: absolute; left: 0px; ">$$\oint_{{S}} \vec{{E}} \cdot \vec{{dA}} = \frac{{q}}{{\epsilon_0}}$$</div> <div style = "display: block; float: right;">$\vec{{E}}$ = The electric field of line charge
        $\vec{{dA}}$ = Closed area around the charge
        $q$ = point charge
        $\epsilon_0$ = permittivity of vacuum</div>
        
        As the direction of the radius vector $\vec{{E}}$ and $\vec{{dA}}$ are same. 
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow \oint_{{S}} E dA \cos\left ( 0 \right ) = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow \oint_{{S}} E dA = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E \oint_{{S}} dA = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E \left [ A \right ]_{{S}} = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E A = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E 2\pi r l = \frac{{q}}{{\epsilon_0}}$$</div> <div style = "display: block; float: right;">$$A = 2\pi r l$$
        $r$ = distance between point and charge
        $l$ = length of the wire</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E = \frac{{1}}{{2\pi r l}} \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E = \frac{{1}}{{2\pi r l}} \frac{{\lambda l}}{{\epsilon_0}}$$</div><div style = "display: block; float: right;">$$q = \lambda l$$
        $\lambda$ = linear charge density</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E = \frac{{1}}{{2\pi r}} \frac{{\lambda}}{{\epsilon_0}}$$</div>

        The electric field of a line charge
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E = \frac{{1}}{{2\pi \epsilon_0}} \frac{{\lambda}}{{r}}$$</div>
        
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = soln_s
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _derive_electric_field_of_plane_charge(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        Derive electric field of a plane charge with Gauss's law.

        <div style = "position: absolute; left: 0px; ">$$\oint_{{S}} \vec{{E}} \cdot \vec{{dA}} = \frac{{q}}{{\epsilon_0}}$$</div>
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        The Gauss's law 
        <div style = "position: absolute; left: 0px; ">$$\oint_{{S}} \vec{{E}} \cdot \vec{{dA}} = \frac{{q}}{{\epsilon_0}}$$</div> <div style = "display: block; float: right;">$\vec{{E}}$ = The electric field of plane charge
        $\vec{{dA}}$ = Closed area around the charge
        $q$ = point charge
        $\epsilon_0$ = permittivity of vacuum</div>
        
        As the direction of the radius vector $\vec{{E}}$ and $\vec{{dA}}$ are same. 
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow \oint_{{S}} E dA \cos\left ( 0 \right ) = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow \oint_{{S}} E dA = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E \oint_{{S}} dA = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E \left [ A \right ]_{{S}} = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E A = \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E 2 A_S = \frac{{q}}{{\epsilon_0}}$$</div> <div style = "display: block; float: right;">$$A = 2 A_S$$
        $A_S$ = area of one of the surface</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E = \frac{{1}}{{2 A_S}} \frac{{q}}{{\epsilon_0}}$$</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E = \frac{{1}}{{2 A_S}} \frac{{\sigma A_S}}{{\epsilon_0}}$$</div><div style = "display: block; float: right;">$$q = \sigma A_S$$
        $\sigma$ = surface charge density</div>
        
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E = \frac{{1}}{{2}} \frac{{\sigma}}{{\epsilon_0}}$$</div>

        The electric field of a plane charge
        <div style = "position: absolute; left: 0px; ">$$\Rightarrow E = \frac{{\sigma}}{{2\epsilon_0}}$$</div>
        
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = soln_s
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
        
    def _problem_3_288(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        A wire bent as a parabola $y = ax^2$ is located in a uniform
        magnetic field of induction $B$, the vector $\mathbf{{B}}$ being perpendicular to
        the plane x, y. At the moment t = 0 a connector starts sliding translationwise from the parabola apex with a constant acceleration iv
        (Fig. 3.78). Find the emf of electromagnetic induction in the loop
        thus formed as a function of y.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        3.288 Obviously, from Lenz's law, the induced current and hence the induced e.m.f. in the loop is anticlockwise. From Faraday's law of electromagnetic
        Here, $\quad d \Phi=\vec{{B}} \cdot d \vec{{S}}=-2 B x d y$
        and from $\quad y=a x^{{2}}, x=\sqrt{{\frac{{y}}{{a}}}}$
        Hence, $\quad \xi_{{\text {{in }}}}=2 B \sqrt{{\frac{{y}}{{a}}}} \frac{{d y}}{{d t}}$
        $=B y \sqrt{{\frac{{8 w}}{{a}}}}$, using $\frac{{d y}}{{d t}} = \sqrt{{2 wy}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_3_289(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        3.289. A rectangular loop with a sliding connector of length 1
        is located in a uniform magnetic field perpendicular to the loop plane
        (Fig. 3.79). The magnetic induction is equal to B. The connector has
        an electric resistance $R_1$, the sides $AB$ and $CD$ have resistances R1
        and $R_2$ respectively. Neglecting the self-inductance of the loop,
        find the current flowing in the connector during its motion with a
        constant velocity v. 
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        3.289 Let us assume, $\vec{{B}}$ is directed into the plane of the loop. Then the motional e.m.f.
        $$
        \begin{{aligned}}
        &\qquad \xi_{{\text {{in }}}}=\left|\int-(\vec{{v}} \times \vec{{B}}) \cdot d \vec{{l}}\right|=v B l \\
        &\text {{ and directed in the same of }}(\vec{{v}} \times \vec{{B}}) \text {{ (Fig.) }} \\
        &\text {{ So, }} i=\frac{{\xi_{{\text {{in }}}}}}{{R+\frac{{R_{{1}} R_{{2}}}}{{R_{{1}}+R_{{2}}}}}}=\frac{{B v l}}{{R+R_{{u}}}}
        \end{{aligned}}
        $$
        As $R_{{1}}$ and $R_{{2}}$ are in parallel connections.
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_3_290(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        3.290. A metal disc of radius a = 25 cm rotates with a constant
        angular velocity $\omega$ = 130 rad/s about its axis. Find the potential
        difference between the centre and the rim of the disc if
        (a) the external magnetic field is absent;
        (b) the external uniform magnetic field of induction B = 5.0 mT 
        is directed perpendicular to the disc. 

        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        3.290 (a) As the metal disc rotates, any free electron also rotates with it with same angular velocity $\omega$,
         and that's why an electron must have an acceleration $\omega^{{2}} r$ directed towards the disc's centre, where 
         $r$ is separation of the electron from the centre of the disc. We know from Newton's second law that if a 
         particle has some acceleration then there must be a net effecetive force on it in the direction of acceleration.
         We also know that a charged particle can be influenced by two fields electric and magnetic. In our problem
         magnetic. field is absent hence we reach at the conslusion that there is an electric field near any electron
         and is directed opposite to the acceleration of the electron.
         If $E$ be the electric field strength at a 
         distance $r$ from the centre of the disc, we have from Newton's second law.
        $$
        \begin{{gathered}}
        F_{{n}}=m w_{{n}} \\
        e E=m r \omega^{{2}}, \quad \text {{ or, }} E=\frac{{m \omega^{{2}} r}}{{e}},
        \end{{gathered}}
        $$
        and the potential difference,
        $$
        \varphi_{{c e n}}-\varphi_{{r i m}}=\int_{{0}}^{{a}} \vec{{E}} \cdot d \vec{{r}}=\int_{{0}}^{{a}} \frac{{m \omega^{{2}} r}}{{e}} d r, \text {{ as }} \vec{{E}} \uparrow \downarrow d \vec{{r}}
        $$
        Thus $\varphi_{{c e n}}-\varphi_{{r i m}}=\Delta \varphi=\frac{{m \omega^{{2}}}}{{e}} \frac{{a^{{2}}}}{{2}}=3 \cdot 0 \mathrm{{nV}}$

        (b) When field $\vec{{B}}$ is present, by definition, of motional e.m.f. :
        $$
        \varphi_{{1}}-\varphi_{{2}}=\int_{{1}}^{{2}}-(\vec{{v}} \times \vec{{B}}) \cdot d \vec{{r}}
        $$
        Hence the sought potential difference,
        $$
        \varphi_{{\text {{cen }}}}-\varphi_{{r i m}}=\int_{{0}}^{{a}}-v B d r=\int_{{0}}^{{a}}-\omega r B d r,(\text {{ as }} v=\omega r)
        $$
        Thus $\varphi_{{\text {{rim }}}}-\varphi_{{\text {{cen }}}}=\varphi=\frac{{1}}{{2}} \omega B a^{{2}}=20 \mathrm{{mV}}$
        (In general $\omega<\frac{{e B}}{{m}}$ so we can neglect the effect discussed in (1) here).
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_3_291(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        3.291. A thin wire $A C$ shaped as a semi-circle of diameter $d=$ $=20 \mathrm{{~cm}}$ rotates with a constant angular
        velocity $\omega=100 \mathrm{{rad}} / \mathrm{{s}}$ in a uniform magnetic field of induction $B=5.0 \mathrm{{mT}}$, with
        $\omega \uparrow \uparrow \mathrm{{B}}$. The rotation axis passes through the end $\boldsymbol{{A}}$ of the wire and is 
        perpendicular to the diameter $A C .$ Find the value of a line integral
        $\int \mathbf{{E}} d \mathbf{{r}}$ along the wire from point $A$ to point $C$. Generalize the obtained result.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        3.291 By definition,
        So,
        $$
        \begin{{gathered}}
        \vec{{E}}=-(\vec{{v}} \times \vec{{B}}) \\
        \int_{{A}} \vec{{E}} \cdot d \vec{{r}}=\int_{{A}}-(\vec{{v}} \times \vec{{B}}) \cdot d \vec{{r}}=\int_{{0}}^{{c}}-y B d r
        \end{{gathered}}
        $$
        But, $v=\omega r$, where $r$ is the perpendicular distance of the point from $A$. 
        Hence, $$\quad \int_{{A}}^{{c}} \vec{{E}} \cdot d \vec{{r}}=\int_{{0}}^{{d}}-\omega B r d r=-\frac{{1}}{{2}} \omega B d^{{2}}=-10 \mathrm{{mV}}$$
        This result can be generalized to a wire $A C$ of arbitary planar shape. We have
        $$
        \begin{{aligned}}
        \int_{{A}}^{{c}} \vec{{E}} \cdot d \vec{{r}}=&-\int_{{A}}^{{c}}(\vec{{v}} \times \vec{{B}}) \cdot d r=-\int_{{A}}^{{C}}((\omega \times \vec{{r}}) \times \vec{{B}}) \cdot d \vec{{r}} \\
        &=-\int_{{A}}^{{c}}(\vec{{B}} \cdot \vec{{r}} \omega-\vec{{B}} \cdot \vec{{\omega}} \vec{{r}}) \cdot d \vec{{r}}
        \end{{aligned}}
        $$
        $$
        =-\frac{{1}}{{2}} B \omega d^{{2}},
        $$
        $d$ being $A C$ and $\vec{{r}}$ being measured from $A$.

        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_3_292(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        3.292. A wire loop enclosing a semi-circle of radius a is located
        on the boundary of a uniform magnetic field of induction B
        (Fig. 3.80). At the moment t = 0 the loop is set into rotation with
        a constant angular acceleration p about an axis 0 coinciding with a
        line of vector B on the boundary. Find the emf induced in the loop
        as a function of time t. Draw the approximate plot of this function.
        The arrow in the figure shows the emf direction taken to be positive
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        3.292 Flux at any moment of time,
        $$
        \left|\Phi_{{t}}\right|=|\vec{{B}} \cdot d \vec{{S}}|=B\left(\frac{{1}}{{2}} R^{{2}} \varphi\right)
        $$
        where $\varphi$ is the sector angle, enclosed by the field. Now, magnitude of induced e.m.f. is given by,
        $$
        \xi_{{\text {{in }}}}=\left|\frac{{d \Phi_{{t}}}}{{d t}}\right|=\left|\frac{{B R^{{2}}}}{{2}} \frac{{d \varphi}}{{d t}}\right|=\frac{{B R^{{2}}}}{{2}} \omega
        $$
        where $\omega$ is the angular velocity of the disc. But as it starts rotating from rest at $t=0$ with an angular acceleration $\beta$ its angular velocity $\omega(t)=\beta t$. So,
        $$
        \xi_{{\text {{in }}}}=\frac{{B R^{{2}}}}{{2}} \beta t
        $$
        According to Lenz law the first half cycle current in the loop is in anticlockwise sense, and in subsequent half cycle it is in clockwise sense. Thus in general, $\xi_{{i n}}=(-1)^{{n}} \frac{{B R^{{2}}}}{{2}} \beta t$, where $n$ in number of half revolutions. The plot $\xi_{{\text {{in }}}}(t)$, where $t_{{n}}=\sqrt{{2 \pi n / \beta}}$ is shown in the answer sheet.
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_3_293(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        3.293. A long straight wire carrying a current I and a $\Pi$-shaped
        conductor with sliding connector are located in the same plane as 
        shown in Fig. 3.81. The connector of length 1 and resistance R slides
        to the right with a constant velocity v. Find the current induced in
        the loop as a function of separation r between the connector and the
        straight wire. The resistance of the $\Pi$-shaped conductor and the selfinductance of the loop are assumed to be negligible. 

        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        3.293 Field, due to the current carrying wire in the region, right to it, is directed into the plane of the paper and its magnitude is given by,
        $B=\frac{{\mu_{{0}}}}{{2 \pi}} \frac{{i}}{{r}}$ where $r$ is the perpendicular distance from the wire. As $B$ is same along the length of the rod thus motional e.m.f.
        $$
        \xi_{{i n}}=\left|-\int_{{1}}^{{2}}(\vec{{v}} \times \vec{{B}}) \cdot d \vec{{l}}\right|=v B l
        $$
        and it is directed in the sense of $(\vec{{v}} \times \vec{{B}})$
        So, current (induced) in the loop,
        $$
        i_{{\text {{in }}}}=\frac{{\xi_{{\text {{in }}}}}}{{R}}=\frac{{1}}{{2}} \frac{{\mu_{{0}} I v i}}{{\pi R r}}
        $$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_3_294(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        3.294. A square frame with side a and a long straight wire carrying
        a current I are located in the same plane as shown in Fig. 3.82. The
        frame translates to the right with a constant velocity v. Find the emf
        induced in the frame as a function of distance x. 
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        3.294 Field, due to the current carrying wire, at a perpendicular distance $x$ from it is given by,
        $$
        B(x)=\frac{{\mu_{{0}}}}{{2 \pi}} \frac{{i}}{{x}}
        $$
        Motional e.m.f is given by $$\left|\int-(\vec{{v}} \times \vec{{B}}) \cdot d \vec{{l}}\right|$$
        There will be no induced e.m.f. in the segments $(2)$ and (4)
        as, $\vec{{v}} \uparrow \uparrow d \vec{{l}}$ and magnitude of e.m.f. induced in 1 and 3 , will be
        $$
        \xi_{{1}}=v\left(\frac{{\mu_{{0}}}}{{2 \pi}} \frac{{i}}{{x}}\right) a \text {{ and }} \xi_{{2}}=v\left(\frac{{\mu_{{0}}}}{{2 \pi}} \frac{{i}}{{(a+x)}}\right) a
        $$
        respectively, and their sense will be in the direction of $(\vec{{v}} \times \vec{{B}})$.
        So, e.m.f., induced in the network $=\xi_{{1}}-\xi_{{2}}\left[\right.$ as $\left.\xi_{{1}}>\xi_{{2}}\right]$
        $$
        =\frac{{a v \mu_{{0}} i}}{{2 \pi}}\left[\frac{{1}}{{x}}-\frac{{1}}{{a+x}}\right]=\frac{{v a^{{2}} \mu_{{0}} i}}{{2 \pi x(a+x)}}
        $$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_3_295(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        3.295. A metal rod of mass m can rotate about a horizontal axis
        0, sliding along a circular conductor of radius a (Fig. 3.83). The
        arrangement is located in a uniform magnetic field of induction B
        directed perpendicular to the ring plane. The axis and the ring are
        connected to an emf source to form a circuit of resistance R. Neglecting the friction, circuit inductance, and ring resistance, find the law
        according to which the source emf must vary to make the rod rotate
        with a constant angular velocity $\omega$. 

        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        3.295 As the rod rotates, an emf.
        $$
        \frac{{d}}{{d t}} \frac{{1}}{{2}} a^{{2}} \theta \cdot B=\frac{{1}}{{2}} a^{{2}} B \omega
        $$
        is induced in it. The net current in the conductor is then $\frac{{\xi(t)-\frac{{1}}{{2}} a^{{2}} B \omega}}{{R}}$ 
        
        A magnetic force will then act on the conductor of magnitude $B I$ per unit length. Its direction will be normal to $B$ and the rod and its torque will be
        
        $$
        \int_{{O}}^{{a}}\left(\frac{{\xi(t)-\frac{{1}}{{2}} a^{{2}} B \omega}}{{R}}\right) d x B x
        $$
        Obviously both magnetic and mechanical torque acting on the C.M. of the rod must be equal but opposite in sense. 
        Then for equilibrium at constant $\omega$
        $$
        \frac{{\xi(t)-\frac{{1}}{{2}} a^{{2}} B \omega}}{{R}} \cdot \frac{{B a^{{2}}}}{{2}}=\frac{{1}}{{2}} m g a \sin \omega t
        $$
        or, $$\quad \xi(t)=\frac{{1}}{{2}} a^{{2}} B \omega+\frac{{m g R}}{{a B}} \sin \omega t=\frac{{1}}{{2 a B}}\left(a^{{3}} B^{{2}} \omega+2 m g R \sin \omega t\right)$$
        (The answer given in the book is incorrect dimensionally.)
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_3_296(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        3.296. A copper connector of mass m slides down two smooth copper bars, set at an angle $\alpha$ to the horizontal, due to gravity (Fig. 3.84).
        At the top the bars are interconnected through a resistance R. The
        separation between the bars is equal to 1. The system is located in
        a uniform magnetic field of induction B, perpendicular to the plane
        in which the connector slides. The resistances of the bars, the connector and the sliding contacts, as well as the self-inductance of the loop,
        are assumed to be negligible. Find the steady-state velocity of the
        connector.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        3.296 From Lenz's law, the current through the connector is directed form $A$ to $B$. Here $\xi_{{\text {{in }}}}=v B l$ between $A$ and $B$ 
        where $v$ is the velocity of the rod at any moment. 
        For the rod, from $F_{{x}}=m w_{{x}}$ 
        or, $\quad m g \sin \alpha-i l B=m w$
        For steady state, acceleration of the rod must be equal to zero.
        Hence, $\quad m g \sin \alpha=$ il $B$ (1)
        But, $i=\frac{{\xi_{{\text {{in }}}}}}{{R}}=\frac{{v B l}}{{R}}$
        From (1) and (2) $v=\frac{{m g \sin \alpha R}}{{B^{{2}} l^{{2}}}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_3_297(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = fr"""
        3.297. The system differs from the one examined in the foregoing
        problem (Fig. 3.84) by a capacitor of capacitance C replacing the
        resistance R. Find the acceleration of the connector. 
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = fr"""
        3.297 From Lenz's law, the current through the copper bar is directed from 1 to 2 or in other words, the induced crrrent in the circuit is in clockwise sense.
        Potential difference across the capacitor plates,
        $$
        \frac{{q}}{{C}}=\xi_{{i n}}$ or, $q=C \xi_{{i n}}
        $$
        Hence, the induced current in the loop, 
        $$
        i=\frac{{d q}}{{d t}}=C \frac{{d \xi_{{i n}}}}{{d t}}
        $$
        But the variation of magnetic flux through the loop is caused by the movement of the bar. So, the induced e.m.f. $\xi_{{i n}}=B l v$
        and, $$\frac{{d \xi_{{i n}}}}{{d t}}=B l \frac{{d v}}{{d t}}=B l w$$
        Hence, $$i=C \frac{{d \xi}}{{d t}}=C B l w$$
        Now, the forces acting on the bars are the weight and the Ampere's force, where $F_{{a m p}}=i l B(C B l w) B=C l^{{2}} B^{{2}} w$
        From Newton's second law, for the rod, $F_{{x}}=m w_{{x}}$
        or, $$m g \sin \alpha-C l^{{2}} B^{{2}} w=m w$$
        Hence $$\quad w=\frac{{m g \sin \alpha}}{{C l^{{2}} B^{{2}}+m}}=\frac{{g \sin \alpha}}{{1+\frac{{l^{{2}} B^{{2}} C}}{{m}}}}$$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    