Forum archive 2000-2006

Michal Charemza - Problems with ijk form of vectors, display of Computed vectors

Michal Charemza - Problems with ijk form of vectors, display of Computed vectors

by Arnold Pizer -
Number of replies: 0
inactiveTopicProblems with ijk form of vectors, display of Computed vectors topic started 9/8/2006; 3:40:35 PM
last post 9/21/2006; 7:14:32 AM
userMichal Charemza - Problems with ijk form of vectors, display of Computed vectors  blueArrow
9/8/2006; 3:40:35 PM (reads: 394, responses: 4)
Hi,

If I set vectors to be displayed in ijk form by using:

$context = Context("Vector"); $context->flags->set(ijk=>1);

Then if I try to compute the cross product of two vectors by:

$a = Vector("1 i + 2 j +3 k"); $b = Vector("4 i + 5 j + 6 k");

$a_cross_b = Compute("$a >< $b");

I get the following error:

I get an Operands of '*' are not of compatible types;

Is there anything I can do to solve this?

Also - the resulting $a_cross_b object when displayed in the "correct" box isn't the calculated cross produce - the "><" operator is still present. Is there a way to have it display as the calculated value in the "correct" box?

(Sorry, I am not working with the most up to date version of Webwork. I hopefully will be soon but at the moment it is beyond my control)

Michal

<| Post or View Comments |>


userDavide P. Cervone - Re: Problems with ijk form of vectors, display of Computed vectors  blueArrow
9/8/2006; 8:05:24 PM (reads: 466, responses: 0)
Remember back when you were getting (10) rather than the 10 that you expected? This is the exactly the reason why those parens were being inserted. Note that "$a >< $b" means "i+2j+3k >< 4i + 5j + 6k", and so you are getting "i + 2j + (3k >< 4i) + 5j + 6k" when you really wanted "(i + 2j + 3k) >< (4i + 5j + 6k)". You should use "($a) >< ($b)" instead.

(I will fix the Parser so that it includes the parens when ijk mode is in effect, but then you will have to be sure to use Context()->texStrings when you use one of these vectors within the BEGIN_TEXT/END_TEXT block. But you would need to do that anyway to get the vectors to show up correctly.)

I'm not sure where you are getting the error about '*'; are you sure it's from this line?

As for seeing "><" in the answer, that's exactly what Compute() is supposed to do for you. One of the things it does is arrange that the string you used to compute the answer is the one shown for the correct answer. So if you don't want that, don't use Compute(). Just use

    $a_cross_b = $a x $b;
since the Parser overloads the "x" operator to do cross product for vectors (it also overloads "." for dot product). This also avoids the parenthesis problem, since this is not going through an intermediate string first; it is pure Perl.

Finally, you don't really need to use Vector("1 i + 2 j + 3 k"), you could just use

    $a = i + 2*j + 3*k;
or
    $a = Vector(1,2,3);
Hope that helps.

Davide

<| Post or View Comments |>


userMichal Charemza - Re: Problems with ijk form of vectors, display of Computed vectors  blueArrow
9/9/2006; 4:54:31 AM (reads: 461, responses: 1)
> You should use "($a) >< ($b)" instead.

I should have said earlier: I tried this and it still came up with the same error.

> I'm not sure where you are getting the error about '*'; are you sure it's from this line?

Just checked, and yes.

> $a_cross_b = $a x $b; This works fine with the ijk flag, and is more convenient - thanks.

> Finally, you don't really need to use Vector("1 i + 2 j + 3 k") Thanks, I didn't know this.

Michal.

<| Post or View Comments |>


userDavide P. Cervone - Re: Problems with ijk form of vectors, display of Computed vectors  blueArrow
9/9/2006; 7:47:01 AM (reads: 539, responses: 0)
I'm not able to reproduce the error about '*'. If you could send the complete problem file, I'll check into it. (You can email it to me if you prefer. There is an email link if you click on my name in the header of this message.)

Also, what version of WW are you using (and have you updated any of the files by hand)?

Davide

<| Post or View Comments |>


userMichal Charemza - Re: Problems with ijk form of vectors, display of Computed vectors  blueArrow
9/21/2006; 7:14:32 AM (reads: 356, responses: 0)
Sorry I've taken such an astronomical time to reply: we have upgrade to a more recent version of Webwork, and now I don't get the error about the *.

Michal

<| Post or View Comments |>