<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>RE: [LON-CAPA-users] Extracting the numerical value from asolve()Maxima command</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>Hi Gerd,<BR>
<BR>
Yes, it works.  It looks similar to the regular expression used to get the expression on either side of an equal sign.<BR>
<BR>
Thank you!<BR>
<BR>
>From Seema.<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: lon-capa-users-bounces@mail.lon-capa.org on behalf of Gerd Kortemeyer<BR>
Sent: Sun 1/29/2012 5:50 PM<BR>
To: Discussion list for LON-CAPA users<BR>
Subject: Re: [LON-CAPA-users] Extracting the numerical value from asolve()Maxima command<BR>
<BR>
Hi,<BR>
<BR>
I think, as you suspected, it was just the regular expression. As the saying goes: "I have a problem. Hmmm, I know, I'll just use a regular expression! Now I have two problems ."<BR>
<BR>
Please see if this works:<BR>
<BR>
<problem><BR>
<script type="loncapa/perl"><BR>
$base1 = &random(2,9,1);<BR>
do {<BR>
   $base2 = &random(2,9,1);<BR>
} while ($base1==$base2);<BR>
<BR>
$a = &random(2,3,1);<BR>
$b = &random(-7,-4,1);<BR>
$c = &random(1,10,1);<BR>
<BR>
<BR>
if (&random(0,1,1)) {<BR>
  $power1 = "$a x";<BR>
  $power2 = "$b x - $c";<BR>
<BR>
  $power1maxima = "$a * x";<BR>
  $power2maxima = "$b * x - $c";<BR>
} else {<BR>
  $power1 = "$a x + $c";<BR>
  $power2 = "$b x";<BR>
<BR>
  $power1maxima = "$a * x + $c";<BR>
  $power2maxima = "$b * x";<BR>
}<BR>
<BR>
<BR>
$solution = &cas('maxima',"float(solve(($power1maxima)*log($base1) = ($power2maxima)*log($base2),x))");<BR>
$solution=~/\=\s*(.+)\s*\]/;<BR>
$answer=$1;<BR>
</script><BR>
<startouttext />Solve for <m>$x$</m> to the nearest hundredth where <m eval='on'>\[$base1^{$power1} = $base2^{$power2}\]</m><BR>
<BR>
$solution<br /><BR>
answer=$answer<endouttext /><BR>
<numericalresponse answer="$answer" format="2F"><BR>
<responseparam name="tol" type="tolerance" description="Numerical Tolerance" default="0.01" /><BR>
<BR>
    <textline readonly="no" /><BR>
  <BR>
</numericalresponse><BR>
</problem><BR>
<BR>
<BR>
<BR>
<BR>
On Jan 28, 2012, at 11:32 AM, Seema Ali wrote:<BR>
<BR>
> It is a little messy, I'm still in construction/learning phase. =]<BR>
><BR>
> <problem><BR>
> <script type="loncapa/perl">$base1 = &random(2,9,1);<BR>
><BR>
> do{<BR>
>    $base2 = &random(2,9,1);<BR>
> }while($base1==$base2);<BR>
><BR>
> $a = &random(2,3,1);<BR>
> $b = &random(4,7,1) * -1;<BR>
> $c = &random(1,10,1);<BR>
><BR>
> $index = &random(1,2,1);<BR>
> $leftright = &choose($index,'left','right');<BR>
><BR>
> if($leftright=='right')<BR>
> {<BR>
>   $power1 = "$a x";<BR>
>   $power2 = "$b x - $c";<BR>
><BR>
>   $power1maxima = "$a * x";<BR>
>   $power2maxima = "$b * x - $c";<BR>
> }<BR>
> else<BR>
> {<BR>
>   $power1 = "$a x + $c";<BR>
>   $power2 = "$b x";<BR>
><BR>
>   $power1maxima = "$a * x + $c";<BR>
>   $power2maxima = "$b * x";<BR>
> }<BR>
><BR>
> $equation = "($power1maxima)*log($base1) = ($power2maxima)*log($base2)";<BR>
><BR>
> $solution = &cas('maxima',"float(solve(($power1maxima)*log($base1) = ($power2maxima)*log($base2),x))");<BR>
> #$solution =~ /(-?\d+(?:\.\d+)?)/;<BR>
> $solution =~ /(-?\d+?(?:\.\d+)?)/;<BR>
> $answer = $1;</script><startouttext />Solve for <m>$x$</m> to the nearest hundredth where <m eval='on'>$base1^{$power1} = $base2^{$power2}</m><BR>
><BR>
> <m eval='on'>$ $equation $solution answer=$answer .............  ------ $</m><endouttext /><BR>
> <numericalresponse answer="$answer"><BR>
> <responseparam name="tol" type="tolerance" description="Numerical Tolerance" default="0.0001" /><BR>
><BR>
>     <textline readonly="no" /><BR>
>   <BR>
> </numericalresponse><BR>
> </problem><BR>
><BR>
><BR>
><BR>
> -----Original Message-----<BR>
> From: lon-capa-users-bounces@mail.lon-capa.org on behalf of Gerd Kortemeyer<BR>
> Sent: Fri 1/27/2012 4:41 PM<BR>
> To: Discussion list for LON-CAPA users<BR>
> Subject: Re: [LON-CAPA-users] Extracting the numerical value from a solve()Maxima command<BR>
><BR>
> Hi,<BR>
><BR>
> Could you please send me the XML source code for your problem?<BR>
><BR>
> Thanks,<BR>
><BR>
> - Gerd.<BR>
><BR>
> On Jan 27, 2012, at 6:14 PM, Seema Ali wrote:<BR>
><BR>
> > Hi,<BR>
> ><BR>
> > This was my attempt to get Maxima to solve the following equation:<BR>
> > $base1^$power1maxima = $base2^$power2maxima<BR>
> > where $power1maxima and $power2maxima are linear equations and<BR>
> > $base1 and $base2 are constant values.<BR>
> ><BR>
> > Below is a snippet of part of my code:<BR>
> ><BR>
> > $solution = &cas('maxima',"float(solve(($power1maxima)*log($base1) = ($power2maxima)*log($base2),x))");<BR>
> > $solution =~ /(-?\d+(?:\.\d+)?)/;<BR>
> > $answer = $1;<BR>
> ><BR>
> ><BR>
> > Here are a couple of examples of some values:<BR>
> ><BR>
> > Example 1:<BR>
> > An equation it is trying to solve: (2 * x)*log(7) = (-7 * x - 7)*log(9)<BR>
> > $solution is [x = -.7980624185332027]<BR>
> > answer=7<BR>
> ><BR>
> > Example 2:<BR>
> > An equation it is trying to solve: (2x)log(4)=(?5x?8)log(3)<BR>
> > $solution is [x=?1063303930517583]<BR>
> > answer=?1063303930517583<BR>
> ><BR>
> > The answer for Example 2 should be -1.063303930517583.  If I double click on the values on the page I get the decimal point, otherwise if I highlight them which is what I did for Example 2, the decimal is missing, which is a separate issue.<BR>
> ><BR>
> > Example 2 also generates this error:<BR>
> > ERROR: Computer's answer is incorrect ("-1.063303930517583"). It is likely that the tolerance range [-1.06340393051758, -1.06320393051758] needs to be adjusted.<BR>
> > This error occurred while processing response 1_7 in part 0<BR>
> ><BR>
> > My tolerance range is 5%.<BR>
> ><BR>
> > I think it is my attempt at a regular expression is probably causing this problem.<BR>
> ><BR>
> > How do I extract the numerical value from a solve command in Maxima?<BR>
> ><BR>
> ><BR>
> > Thanks.<BR>
> ><BR>
> > _______________________________________________<BR>
> > LON-CAPA-users mailing list<BR>
> > LON-CAPA-users@mail.lon-capa.org<BR>
> > <A HREF="http://mail.lon-capa.org/mailman/listinfo/lon-capa-users">http://mail.lon-capa.org/mailman/listinfo/lon-capa-users</A><BR>
><BR>
> _______________________________________________<BR>
> LON-CAPA-users mailing list<BR>
> LON-CAPA-users@mail.lon-capa.org<BR>
> <A HREF="http://mail.lon-capa.org/mailman/listinfo/lon-capa-users">http://mail.lon-capa.org/mailman/listinfo/lon-capa-users</A><BR>
><BR>
><BR>
> _______________________________________________<BR>
> LON-CAPA-users mailing list<BR>
> LON-CAPA-users@mail.lon-capa.org<BR>
> <A HREF="http://mail.lon-capa.org/mailman/listinfo/lon-capa-users">http://mail.lon-capa.org/mailman/listinfo/lon-capa-users</A><BR>
<BR>
_______________________________________________<BR>
LON-CAPA-users mailing list<BR>
LON-CAPA-users@mail.lon-capa.org<BR>
<A HREF="http://mail.lon-capa.org/mailman/listinfo/lon-capa-users">http://mail.lon-capa.org/mailman/listinfo/lon-capa-users</A><BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>