'''
Created on 20-Jan-2022

@author: bthakur
'''

import inspect
import traceback
import random
import numpy as np
from sympy import (latex, Symbol, symbols,
                   )

from xv.util import toIntOrFloat, listAttr
from xv.km.storeddata import BaseStoredQuestions

class ElectricCurrentStoredQuestions(BaseStoredQuestions):
    _QUESTION_KEYWORDS = None
    
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        pass
    
    def get_question_q3_147(self):
        keywords = [
            'electric currents',
            '3.147'
            ]
       
        prob_s = fr"""
		3.147. A long cylinder with uniformly charged surface and crosssectional radius $a=1.0 \mathrm{{~cm}}$ moves with a constant velocity $v=10 \mathrm{{~m}} / \mathrm{{s}}$ along its axis. An electric field strength at the surface of the cylinder is equal to $E=0.9 \mathrm{{kV}} / \mathrm{{cm}}$. Find the resulting convection current, that is, the current caused by mechanical transfer of a charge.

        """
        
        
        soln_s = fr"""
        The convection current is
		$\displaystyle I=\frac{{d q}}{{d t}} \quad \text{{(1)}}$
		here, $d q=\lambda d x$, where $\lambda$ is the linear charge density.
		But, from the Gauss' theorem, electric field at the surface of the cylinder,
		$\displaystyle E=\frac{{\lambda}}{{2 \pi \varepsilon_{{0}} a}}$
		Hence, substituting the value of $\lambda$ and subsequently of $d q$ in Eqs. (1), we get
		$\displaystyle \begin{{gathered}} I=\frac{{2 E \pi \varepsilon_{{0}} a d x}}{{d t}} \\ =2 \pi \varepsilon_{{0}} E a v, \text {{ as }} \frac{{d x}}{{d t}}=v\end{{gathered}}$
		
        """
        
        answer_s = fr"""
        $I=2 \pi \varepsilon_{{0}} a E v=0.5 \mu \mathrm{{A}}$.
        """
        result = {
            'keywords': keywords,
            'prob_s': prob_s.strip(),
            'soln_s': soln_s.strip(),
            'answer_s': answer_s.strip(),
            }
        return result

    def get_question_q3_148(self):
        keywords = [
            'electric currents',
            '3.148'
            ]
       
        prob_s = fr"""
		3.148. An air cylindrical capacitor with a dc voltage $V=200 \mathrm{{~V}}$ applied across it is being submerged vertically into a vessel filled with water at a velocity $v=5.0 \mathrm{{~mm}} / \mathrm{{s}}$. The electrodes of the capacitor are separated by a distance $d=2.0 \mathrm{{~mm}}$, the mean curvature radius of the electrodes is equal to $r=50 \mathrm{{~mm}}$. Find the current flowing in this case along lead wires, if $d \ll r$.

        """
        
        
        soln_s = fr"""
        Since $d \ll r$, the capacitance of the given capacitor can be calculated using the formula for a parallel plate capacitor. Therefore if the water (permittivity $\varepsilon$ ) is introduced up to a height $x$ and the capacitor is of length $l$, we have,
		$\displaystyle C=\frac{{\varepsilon \varepsilon_{{0}} \cdot 2 \pi r x}}{{d}}+\frac{{\varepsilon_{{0}}(l-x) 2 \pi r}}{{d}}=\frac{{\varepsilon_{{0}} 2 \pi r}}{{d}}(\varepsilon x+l-x)$
		Hence charge on the plate at that instant, $q=C V$
		Again we know that the electric current intensity,
		$\displaystyle \begin{{gathered}} I=\frac{{d q}}{{d t}}=\frac{{d(C V)}}{{d t}} \\ =\frac{{V \varepsilon_{{0}} 2 \pi r}}{{d}} \frac{{d(\varepsilon x+l-x)}}{{d t}}=\frac{{V 2 \pi r \varepsilon_{{0}}}}{{d}}(\varepsilon-1) \frac{{d x}}{{d t}} \end{{gathered}}$
		But,
		$\displaystyle \frac{{d x}}{{d t}}=v$
		So,
		$\displaystyle I=\frac{{2 \pi r \varepsilon_{{0}}(\varepsilon-1) V}}{{d}} v=0.11 \mu \mathrm{{A}}$
		
		
        """
        
        answer_s = fr"""
        $I \approx 2 \pi \varepsilon_{{0}}(\varepsilon-1) r v V / d=0.11 \mu \mathrm{{A}}$.
        """
        result = {
            'keywords': keywords,
            'prob_s': prob_s.strip(),
            'soln_s': soln_s.strip(),
            'answer_s': answer_s.strip(),
            }
        return result

    def get_question_q3_149(self):
        keywords = [
            'electric currents',
            '3.149'
            ]
       
        prob_s = fr"""
		3.149. At the temperature $0^{{\circ}} \mathrm{{C}}$ the electric resistance of conductor 2 is $\eta$ times that of conductor 1. Their temperature coefficients of resistance are equal to $\alpha_{{2}}$ and $\alpha_{{1}}$ respectively. Find the temperature coefficient of resistance of a circuit segment consisting of these two conductors when they are connected
		(a) in series; (b) in parallel.
		
        """
        
        
        soln_s = fr"""
		We have, $R_{{t}}=R_{{0}}(1+\alpha t),(1)$
		where $R_{{t}}$ and $R_{{0}}$ are resistances at $t^{{\circ}} \mathrm{{C}}$ and $0^{{\circ}} \mathrm{{C}}$ respectively and $\alpha$ is the mean temperature coefficient of resistance.
		So, $\quad R_{{1}}=R_{{0}}\left(1+\alpha_{{1}} t\right)$ and $R_{{2}}=\eta R_{{0}}\left(1+\alpha_{{2}} t\right)$
		(a) In case of series combination, $R=\Sigma R_{{i}}$ 
        so
		$\displaystyle \begin{{aligned}} R &=R_{{1}}+R_{{2}}=R_{{0}}\left[(1+\eta)+\left(\alpha_{{1}}+\eta \alpha_{{2}}\right) t\right.\\ &=R_{{0}}(1+\eta)\left[1+2 \frac{{\alpha_{{1}}+\eta \alpha_{{2}}}}{{1+\eta}} t\right]\end{{aligned}}$
		Comparing Eqs. (1) and (2), we conclude that temperature co-efficient of resistance of the circuit,
		$\displaystyle \alpha=\frac{{\alpha_{{1}}+\eta \alpha_{{2}}}}{{1+\eta}}$
		(b) In parallel combination
		$\displaystyle R=\frac{{R_{{0}}\left(1+\alpha_{{1}} t\right) R_{{0}} \eta\left(1+\alpha_{{2}} t\right)}}{{R_{{0}}\left(1+\alpha_{{1}} t\right)+\eta R_{{0}}\left(1+\alpha_{{2}} t\right)}}=R^{{\prime}}\left(1+\alpha^{{\prime}} t\right), \text {{ where }} R^{{\prime}}=\frac{{\eta R_{{0}}}}{{1+\eta}}$
		Now, neglecting the terms, proportional to the product of temperature coefficients, as being very small, we get,
		$\displaystyle \alpha^{{\prime}} \approx \frac{{\eta \alpha_{{1}}+\alpha_{{2}}}}{{1+\eta}}$
		
		
        """
        
        answer_s = fr"""
        (a) $\alpha=\left(\alpha_{{1}}+\eta \alpha_{{2}}\right) /(1+\eta) ;$ (b) $\alpha \approx\left(\alpha_{{2}}+\eta \alpha_{{1}}\right) /(1+\eta)$.
        """
        result = {
            'keywords': keywords,
            'prob_s': prob_s.strip(),
            'soln_s': soln_s.strip(),
            'answer_s': answer_s.strip(),
            }
        return result

    def get_question_q3_150(self):
        keywords = [
            'electric currents',
            '3.150'
            ]
       
        prob_s = fr"""
        FIX THIS 
    
		3.150. Find the resistance of a wire frame $3.35$. shaped as a cube (Fig. 3.35) when measured between points
		(a) 1-7; (b) 1-2; (c) 1-3.
		The resistance of each edge of the frame is $R$
		
        """
        
        
        soln_s = fr"""
		(a) The currents are as shown. From Ohm's law applied between 1 and 7 via 1487 (say)
		
		$\displaystyle I R_{{\mathrm{{eq}}}}=\frac{{I}}{{3}} R+\frac{{I}}{{6}} R+\frac{{I}}{{3}} R=\frac{{5}}{{6}} R I$
		Thus,
		$\displaystyle R_{{\mathrm{{eq}}}}=\frac{{5 R}}{{6}}$
		(b) Between 1 and 2 from the loop 14321,
		$\displaystyle I_{{1}} R=2 I_{{2}} R+I_{{3}} R \text {{ or, }} I_{{1}}=I_{{3}}+2 I_{{2}}$
		From the loop 48734,
		$\displaystyle \left(I_{{2}}-I_{{3}}\right) R+2\left(I_{{2}}-I_{{3}}\right) R+\left(I_{{2}}-I_{{3}}\right) R=I_{{3}} R .$
		or,
		$\displaystyle 4\left(I_{{2}}-I_{{3}}\right)=I_{{3}} \text {{ or }} I_{{3}}=\frac{{4}}{{5}} I_{{2}}$
		so
		$\displaystyle I_{{1}}=\frac{{14}}{{5}} I_{{2}}$
		Then, $\displaystyle \left(I_{{1}}+2 I_{{2}}\right) R_{{\text {{eq }}}}=\frac{{24}}{{5}} I_{{2}} R_{{\text {{eq }}}}=I_{{1}} R=\frac{{14}}{{5}} I_{{2}} R$
		

		
        """
        
        answer_s = fr"""
        (a) $5 / 6 R$; (b) $7 / 12 R$; (c) $3 / 4 R$.
        """
        result = {
            'keywords': keywords,
            'prob_s': prob_s.strip(),
            'soln_s': soln_s.strip(),
            'answer_s': answer_s.strip(),
            }
        return result

    def get_question_q3_151(self):
        keywords = [
            'electric currents',
            '3.151'
            ]
       
        prob_s = fr"""
        3.151. At what value of the resistance $R_{{x}}$ in the circuit shown in Fig. $3.36$ will the total resistance between points $A$ and $B$ be independent of the number of cells?

        """
        
        
        soln_s = fr"""
		3.151 Total resistance of the circuit will be independent of the number of cells,
		if
		$\displaystyle R_{{x}}=\frac{{\left(R_{{x}}+2 R\right) R}}{{R_{{x}}+2 R+R}}$
		or,
		$\displaystyle R_{{x}}^{{2}}+2 R R_{{x}}-2 R^{{2}}=0$
		On solving and rejecting the negative root of the quadratic equation, we have,
		$\displaystyle R_{{x}}=R(\sqrt{{3}}-1)$
		
		
        """
        
        answer_s = fr"""
        $R_{{x}}=R(\sqrt{{3}}-1)$.
        """
        result = {
            'keywords': keywords,
            'prob_s': prob_s.strip(),
            'soln_s': soln_s.strip(),
            'answer_s': answer_s.strip(),
            }
        return result

    def get_question_q3_151(self):
        keywords = [
            'electric currents',
            '3.151'
            ]
       
        prob_s = fr"""
        3.151. At what value of the resistance $R_{{x}}$ in the circuit shown in Fig. $3.36$ will the total resistance between points $A$ and $B$ be independent of the number of cells?

        """
        
        
        soln_s = fr"""
		3.151 Total resistance of the circuit will be independent of the number of cells,
		if
		$\displaystyle R_{{x}}=\frac{{\left(R_{{x}}+2 R\right) R}}{{R_{{x}}+2 R+R}}$
		or,
		$\displaystyle R_{{x}}^{{2}}+2 R R_{{x}}-2 R^{{2}}=0$
		On solving and rejecting the negative root of the quadratic equation, we have,
		$\displaystyle R_{{x}}=R(\sqrt{{3}}-1)$
		
		
        """
        
        answer_s = fr"""
        $R_{{x}}=R(\sqrt{{3}}-1)$.
        """
        result = {
            'keywords': keywords,
            'prob_s': prob_s.strip(),
            'soln_s': soln_s.strip(),
            'answer_s': answer_s.strip(),
            }
        return result

    def get_question_q3_sample(self):
        keywords = [
            'electric currents',
            ]
       
        prob_s = fr"""
        
        """
        
        
        soln_s = fr"""
        
        """
        
        answer_s = fr"""
        """
        result = {
            'keywords': keywords,
            'prob_s': prob_s.strip(),
            'soln_s': soln_s.strip(),
            'answer_s': answer_s.strip(),
            }
        return result

   
    pass
#class LogarithmStoredQuestions:
