For problem in ECE electromagnetics, we use standard vectors xyz (or Latex \hat{{\bf x}}, etc. when writing problems, we can use the Latex notation, which agrees with the texts. But entering answers, we seem to be stuck using ijk, although we can change the i to x in the rendering of the answer. See example below. Can we change the context to accept xyz and render it xyz?

# Problem for 'NCSU ECE303 Ulaby 7Ed P4.15'.

# WeBWorK problem written by H. J. Trussell, <hjt@ncsu.edu>

# ENDDESCRIPTION

## DBsubject(Electrical Engineering)

## DBchapter(CHAPTER 4 ELECTROSTATICS)

## DBsection(Section 4-3: Coulomb's Law)

## Institution(North Carolina State University)

## Autho(H. J. Trussell)

## TitleText1('Fundamentals of Applied Electromagnetics')

## AuthorText1('Fawwaz T. Ulaby', 'Umberto Ravaioli')

## EditionText1('7')

## Problem1('4.15')

## Keywords('electrostatic','Coulomb')

## Resources()

DOCUMENT(); # This should be the first executable line in the problem.

loadMacros(

"PGstandard.pl",

"MathObjects.pl",

"AnswerFormatHelp.pl",

"parserFunction.pl",

"answerHints.pl",

"PGcourse.pl",

"parserVectorUtils.pl",

);

TEXT(beginproblem());

Context("Vector");

Context()->flags->set(

tolerance => 0.01,

tolType => "relative",

ijk=>1,

);

Context()->constants->set(

i => {TeX => "\mathit{\bf{ \hat{x}}}"},

j => {TeX => "\mathit{\bf{ \hat{y}}}"},

k => {TeX => "\mathit{\bf{ \hat{z}}}"},

);

$rho=random(4,7,1); #rho*10^6

$phiinv=random(3,5,1);

$rv=random(2,4,0.5); #cm

$zb=random(4,7,1);#cm

$zc=-$zb;

$za=0;

#Debug

#$rho=5;$phiinv=4;$rv=2;$zb=5;$zc=-5;

$eps0=1/36/pi; #eps*10^9

$Zv=$rv;

$Eax=-$rho/4/pi/$eps0*$rv/100*$rv/100*sin(pi/$phiinv)/($rv/100)**3;

$Eay=$rho/4/pi/$eps0*$rv/100*$rv/100*(cos(pi/$phiinv)-1)/($rv/100)**3;

$Eaz=0;

$Ebx=-$rho/4/pi/$eps0*$rv/100*$rv/100*sin(pi/$phiinv)*(1/(($rv/100)**2+($zb/100)**2)**1.5);

$Eby=$rho/4/pi/$eps0*$rv/100*$rv/100*(cos(pi/$phiinv)-1)*(1/(($rv/100)**2+($zb/100)**2)**1.5);

$Ebz=$rho/4/pi/$eps0*$rv/100*$zb/100*(1/(($rv/100)**2+($zb/100)**2)**1.5)*pi/$phiinv;

$Ecx=-$rho/4/pi/$eps0*$rv/100*$rv/100*sin(pi/$phiinv)*(1/(($rv/100)**2+($zc/100)**2)**1.5);

$Ecy=$rho/4/pi/$eps0*$rv/100*$rv/100*(cos(pi/$phiinv)-1)*(1/(($rv/100)**2+($zc/100)**2)**1.5);

$Ecz=$rho/4/pi/$eps0*$rv/100*$zc/100*(1/(($rv/100)**2+($zc/100)**2)**1.5)*pi/$phiinv;

$Veca=Vector($Eax,$Eay,$Eaz);

$Vecb=Vector($Ebx,$Eby,$Ebz);

$Vecc=Vector($Ecx,$Ecy,$Ecz);

Context()->texStrings;

BEGIN_TEXT

$PAR

Electric charge is distributed along an arc located in the x-y plane and defined by \(r=$rv (cm)\) and \( 0 \leq \phi \leq \pi/4 \). If \( \rho_l = $rho (\mu C/m)\), find $BBOLD \(E\) $EBOLD at origin, \(z=$zb (cm)\) and \(z=$zc (cm) \). $BR

$BBOLD Note: The expected answer is in the form of "a*i+b*j+c*k" where \(\langle \hat {\bf i}, \hat{ \bf j}, \hat{ \bf k} \rangle \) represent \( \langle \hat{ \bf x}, \hat{ \bf y}, \hat{ \bf z} \rangle \) as Webwork only accepts "i", "j","k" as the unit vector in your answer. \(a,b,c\) are the vector coefficients (numerical values) to be determined by you. Use \(\varepsilon_0=\frac{10^{-9}}{36 \pi}\). Make sure the unit is consistent. $EBOLD $PAR

a) At \(z=0\), $BBOLD \(E \) $EBOLD=\{ans_rule(20)\} \((kV/m)\) \{ AnswerFormatHelp("vectors") \} $BR

b) At \(z=$zb cm\), $BBOLD \(E \) $EBOLD=\{ans_rule(20)\} \((kV/m)\) \{ AnswerFormatHelp("vectors") \} $BR

c) At \(z=$zc cm\), $BBOLD \(E \) $EBOLD=\{ans_rule(20)\} \((kV/m)\) \{ AnswerFormatHelp("vectors") \}

END_TEXT

Context()->normalStrings;

ANS( $Veca->cmp() );

ANS( $Vecb->cmp() );

ANS( $Vecc->cmp() );

##############################

# Solution

Context()->texStrings;

BEGIN_SOLUTION

$PAR

For an arc of charge, \(dl=r d \phi=\frac{$rv}{100} d \phi \), and \( \hat{\bf R}'=-\hat{\bf x} $rv/100 cos \phi -\hat{\bf y} $rv/100 sin \phi + \hat{\bf z} z\). Use of Eq. 4.21c from the textbook for line of charge gives: $BR

\(E=\Large \frac{1}{4 \pi \varepsilon_0} \int_{l'} \hat{ \bf R}'\frac{\rho_l dl'}{ R'^2} \) $BR

\(=\Large \frac{1}{4 \pi \varepsilon_0} \int_{\phi=0}^{\frac{\pi}{$phiinv}} \rho_l \frac{(-\hat{ \bf x} \frac{$rv}{100} cos \phi -\hat{ \bf y} \frac{$rv}{100} sin \phi + \hat{ \bf z} z)}{((\frac{$rv}{100})^2+z^2)^{1.5}} \cdot \frac{$rv}{100} d \phi \)

$PAR

a) At \(z=0\), $BBOLD \(E\) $EBOLD \(=$Veca (kV/m)\) $BR

b) At \(z=$zb\), $BBOLD \(E\) $EBOLD \(=$Vecb (kV/m)\) $BR

c) At \(z=$zc\), $BBOLD \(E\) $EBOLD \(=$Vecc (kV/m)\)

END_SOLUTION

ENDDOCUMENT(); # This should be the last executable line in the problem.

Context("Vector"); Context()->flags->set(ijk => 1); Context()->variables->remove('x','y','z'); Context()->constants->add( x => {value => i, TeX => '\boldsymbol{\hat x}', perl => 'i'}, y => {value => j, TeX => '\boldsymbol{\hat y}', perl => 'j'}, z => {value => k, TeX => '\boldsymbol{\hat z}', perl => 'k'}, ); Context()->constants->set( i => {string => 'x', TeX => '\boldsymbol{\hat x}'}, j => {string => 'y', TeX => '\boldsymbol{\hat y}'}, k => {string => 'z', TeX => '\boldsymbol{\hat z}'}, );may give you what you want. Unfortunately, this still means that

`i`

, `j`

and `k`

are still defined and can be used by students to enter answers (though they will display as x, y, and z), so if you don't want that, you would have to work much harder. The code that handles ijk-mode requires that they be defined, so to get around that, you would have to create your own subclasses of the vector object (for both the Parser and Value libraries) and override the code that uses i, j, and k.
it might be good to modify the vector objects to take the letters used from a context flag.

thanks - that does the trick and will serve us well. If the students want to input ijk that is fine with us. Our instructions will say use xyz. Since that is what is being taught in class, I doubt we'll have a problem.

Joel