### Display reduced formulas in Tex

by Joel Trussell -The command

$f11 = Formula(" $r1 e**(i *pi/$frac_theta1) ")->reduce;

works fine but I want to display the formula in Tax mode

in the text section, if I write

Write \( z_2 = $r2 e^{j \pi/$frac_theta2} = $r2 exp(j \pi/$frac_theta2) \)

I get the symbol pi and the fraction I want but when $frac_theta2 is negative, it puts -2 in the denominator. If I try to print $f11, then I don't get the exponential notation but the ^ symbol

How do I produce a simplified (reduced) formula in Tex?

Code follows

## Complex Numbers and the Complex Plane

## ENDDESCRIPTION

## KEYWORDS('Complex', 'Plane')

## Tagged by nhamblet

## DBsubject('Algebra')

## DBchapter('Equations and Inequalities')

## DBsection('Complex Numbers')

## Date('')

## Author('')

## Institution('Rochester')

## TitleText1('')

## EditionText1('')

## AuthorText1('')

## Section1('')

## Problem1('')

DOCUMENT() ;

loadMacros(

"PGstandard.pl",

"MathObjects.pl",

"PGcourse.pl"

) ;

#sub i (); #make i act like the imaginary unit.

$showPartialCorrectAnswers=1;

TEXT(beginproblem()) ;

$r1 =random(1,9,1);

do {$r2 = random(2,9,1);} until ($r2 != $r1);

$frac_theta1 = list_random(0,-2,2,-3,3,-4,4,-6,6);

do {$frac_theta2 = list_random(0,-2,2,-3,3,-4,4,-6,6);} until ($frac_theta2 != $frac_theta1);

$theta1 = pi/$frac_theta1;

$theta2 = pi/$frac_theta2;

$x1 = cos($theta1);

$y1 = sin($theta1);

$x2 = cos($theta2);

$y2 = sin($theta2);

Context("Complex");

$f11 = Formula(" $r1 e**(i *pi/$frac_theta1) ")->reduce;

$f12 = Formula("$r1 exp(i *pi/$frac_theta1) ")->reduce;

$f21 = Formula(" $r2 e**(i *pi/$frac_theta2) ")->reduce;

$f22 = Formula("$r2 exp(i *pi/$frac_theta2) ")->reduce;

BEGIN_TEXT

Using Euler's formula

\[ e^{i\theta} =\cos(\theta) + i \sin(\theta). \]

$PAR

Write \(z_1 = \)$f11 = $f12 in rectangular coordinates $BR

\(z_1 =\)\{ans_rule(10)\} + j\{ans_rule(10)\}

$PAR

Write \( z_2 = $r2 e^{j \pi/$frac_theta2} = $r2 exp(j \pi/$frac_theta2) \) $BR

$f21 $f22 $BR

\(z_2 =\)\{ans_rule(10)\} + j\{ans_rule(10)\}

END_TEXT

ANS num_cmp($x1 );

ANS num_cmp($y1);

ANS num_cmp($x2);

ANS num_cmp($y2);

ENDDOCUMENT() ;

### Re: Display reduced formulas in Tex

by Murphy Waggoner -On the other hand, for latex to interpret formulas correctly, you need to add texStrings to the context.

Here I have modified your code. See highlighting below. Both MathObjects and latex work nicely.

## Complex Numbers and the Complex Plane

## ENDDESCRIPTION

## KEYWORDS('Complex', 'Plane')

## Tagged by nhamblet

## DBsubject('Algebra')

## DBchapter('Equations and Inequalities')

## DBsection('Complex Numbers')

## Date('')

## Author('')

## Institution('Rochester')

## TitleText1('')

## EditionText1('')

## AuthorText1('')

## Section1('')

## Problem1('')

DOCUMENT() ;

loadMacros(

"PGstandard.pl",

"MathObjects.pl",

"PGcourse.pl"

) ;

#sub i (); #make i act like the imaginary unit.

$showPartialCorrectAnswers=1;

TEXT(beginproblem()) ;

$r1 =random(1,9,1);

do {$r2 = random(2,9,1);} until ($r2 != $r1);

$frac_theta1 = list_random(0,-2,2,-3,3,-4,4,-6,6);

do {$frac_theta2 = list_random(0,-2,2,-3,3,-4,4,-6,6);} until ($frac_theta2 != $frac_theta1);

$theta1 = pi/$frac_theta1;

$theta2 = pi/$frac_theta2;

$x1 = cos($theta1);

$y1 = sin($theta1);

$x2 = cos($theta2);

$y2 = sin($theta2);

Context("Complex");

$f11 = Formula(" $r1 e**(i *pi/$frac_theta1) ")->reduce;

$f12 = Formula("$r1 exp(i *pi/$frac_theta1) ")->reduce;

$f21 = Formula(" $r2 e**(i *pi/$frac_theta2) ")->reduce;

$f22 = Formula("$r2 exp(i *pi/$frac_theta2) ")->reduce;

Context()->texStrings; # adds tex string capability to the context

BEGIN_TEXT

Using Euler's formula

\[ e^{i\theta} =\cos(\theta) + i \sin(\theta). \]

$PAR

Write \(z_1 = $f11 = $f12\) in rectangular coordinates $BR

\(z_1 =\)\{ans_rule(10)\} + j\{ans_rule(10)\}

$PAR

Write \( z_2 = $r2 e^{j \pi/$frac_theta2} = $r2 \exp(j \pi/$frac_theta2) \) $BR

\(z_2 =\)\{ans_rule(10)\} + j\{ans_rule(10)\}

END_TEXT

ANS num_cmp($x1 );

ANS num_cmp($y1);

ANS num_cmp($x2);

ANS num_cmp($y2);

ENDDOCUMENT() ;

Reply

You are logged in as Murphy Waggoner (Logout)

UsingWW

### Re: Display reduced formulas in Tex

by Joel Trussell -### Re: Display reduced formulas in Tex

by Davide Cervone -Context()->normalStrings();after the

`END_TEXT`

. It is not strictly necessary in this case, but is good practice and will avoid potential problems in later parts of the problem (if you use MathObjects in strings after the `END_TEXT`

).