WeBWorK Main Forum

vectors - using ijk and xyz

vectors - using ijk and xyz

by Joel Trussell -
Number of replies: 2
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>

## DBsubject(Electrical Engineering)
## 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.




tolerance => 0.01,
tolType => "relative",

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
$rv=random(2,4,0.5); #cm


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






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") \}


ANS( $Veca->cmp() );
ANS( $Vecb->cmp() );
ANS( $Vecc->cmp() );
# Solution
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 \)
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)\)


ENDDOCUMENT(); # This should be the last executable line in the problem.
In reply to Joel Trussell

Re: vectors - using ijk and xyz

by Davide Cervone -
I think that using

Context()->flags->set(ijk => 1);
  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'},
  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.

In reply to Davide Cervone

Re: vectors - using ijk and xyz

by Joel Trussell -
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.