Forums

Search results: 163

trying to take a step back from my more ambitious attempt to make a specialized context, I decided to see how to just add a formula to an existing context worked.

I used the code shown in "Adding new functions" in the webwork wiki. But that fails in a similar manner to what I was experiencing in the other problem I posted yesterday.

The error I get is this:

If I try to use log2() in the problem.

Any idea why this is happening?

The pg code is below:

#############################################
#  Initialization

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"PGgraphmacros.pl",
"unionTables.pl",
"parserFunction.pl"
);

TEXT(beginproblem());

package my::Function::numeric;
   our @ISA = ('Parser::Function::numeric');     # subclass of Parser::Function::numeric
 
   my $log2 = CORE::log(2);                      # cached value of log(2)
 
   sub log2 {                                    # the routine for computing log base 2
     shift; my $x = shift;
     return CORE::log($x)/$log2;
   }
 
   package main; 

Context("Numeric");

 Context()->functions->add(
     log2 => {class => 'my::Function::numeric', TeX => '\log_2', nocomplex => 1},
   );

$refreshCachedImages = 1;

##############################################
#  Setup

$tst = log2(2); # 

#############################################
#  Main text

Context()->texStrings;
BEGIN_TEXT

test

Test 1 = $tst

END_TEXT
Context()->normalStrings;

###############################################
#  Answer evaluation

$showPartialCorrectAnswers = 1;

############################
#  Solution

ENDDOCUMENT();

WeBWorK Problems -> Creating a special context?

by Joel Therrien -
Hello,

After having spent many years authoring problems for some electrical engineering courses I have taught, I decided it was time to try and make the process easier and better looking (so immediately, you probably know that I so far have accomplished neither of those goals!).

There are a number of functions and constants that I use in these courses (I will focus on the quantum mechanics course I am writing problems for currently) which I don't wish to redefine for each and every problem. Therefore I figured this would be the perfect time to try making my own specialized context, which I titled 'Quantum'. I will show the 'contextQuantum.pl' file I created and show a test problem below.

I put the context file in the macros directory for my course and you can see that I load it and call it in the problem without that generating any errors. Though I did note that even if the file or context is spelled wrong, webwork does not throw any errors, so that isn't saying much by itself.

Now if I try to use a constant, say h_bar, directly in the problem, for example:

$test = h_bar;

Printing $test in the problem text just displays "h_bar" and not the value. But if I use Compute(h_bar); then the number comes through. But the built in constants, such as "pi" work just fine as one would expect.

Similar issue for functions, they only evaluate when called within functionParser(). I put comments next to the different scenarios I tried and what errors I got when processing the test.pg file

Any guidance would be greatly appreciated. Though there is ample documentation on writing your own contexts, there doesn't seem to be much out there on having this reside in it's own contextName.pl file, or not much that I could find. Github is a nice resource to see how others treat this, but I found a wide variation in styles, which makes it hard to figure out what is or isn't necessary to get this to work. And apologies in advance for rookie Perl mistakes; this is my first time diving this deep into it!

Here is the test.pg file I am using:

## DBsubject('Quantum Mechanics')
## DBchapter('Exam')
## DBsection('Wavefunctions')
## Date('03/18/2014')
## Author('Joel Therrien')
## Institution('UML')


#############################################
#  Initialization

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"PGgraphmacros.pl",
"unionTables.pl",
"parserFunction.pl",
"contextQuantum.pl"
);

TEXT(beginproblem());

$refreshCachedImages = 1;


##############################################
#  Setup

Context("Quantum");

$tst = context::Quantum::Tunneling(1,2); # This one works just fine

# $tst = Compute(Tunneling(1,2)); # This one throws the following error: Undefined subroutine &main::Tunneling called at line 35 of (eval 2857)

parserFunction( "fTest(t)" => "context::Quantum::Tunneling(1,t)"); #This one throws the following error: 'context' is not defined in this context;

parserFunction( "fTest(t)" => "Tunneling(1,t)"); # This one throws the following error: Can't locate object method "weaken" via package "context::Quantum::Tunneling"

$tst2 = fTest(2); 

#############################################
#  Main text

Context()->texStrings;
BEGIN_TEXT

test

Test 1 = $tst

test 2 = $tst2

END_TEXT
Context()->normalStrings;

###############################################
#  Answer evaluation

$showPartialCorrectAnswers = 1;

############################
#  Solution

ENDDOCUMENT(); 

Here is the contextQuantum.pl file:

##########################################################################
#
# Hopefully this will become a library of quantum functions and constants
#

loadMacros("MathObjects.pl");

my $h = 6.6E-34; #Planck's constant
my $h_bar = 1.05E-34; #Planck's reduced constant
my $m_e = 9.11E-31; #electron rest mass

sub _contextQuantum_init {
my $context = $main::context{Quantum} = Parser::Context->getCopy("Numeric");

       $context->flags->set(
                            zeroLevel => 1E-50,
                            zeroLevelTol => 1E-50
 );
       $context->constants->add('h' => {value => $h, TeX => '\boldsymbol{h}'},
   'hbar' => {value => $h_bar, Tex => '\boldsymbol{\hbar}'},
 'me' => {value => $m_e, TeX => '\boldsymbol{m_{e}}'}
   );
    $context->functions->add(
                                                              Tunneling => {class => 'context::Quantum::Tunneling'}
                                                  );
}

package context::Quantum;
our @ISA = qw(Parser::Function::numeric2); 

sub Tunneling {
  my ($n,$r) = @_; my $T = 1;
  $T=2.3*$n;
  return $T
}

package main;

1;

~~~~

The following search terms occur only in the HTML markup of this message: refresh

Hello all.

This is the nature of the error: upon viewing any problem in the Demo homework set, WW reported several warnings/errors to do with lines 387, 388, 398, 402, and 410 of ImageGenerator.pm. I looked at these lines in ImageGenerator.pm but I wasn't able to figure out what the problem was.

There were references to LaTeX in that part of ImageGenerator.pm, so thinking the problem was with texlive, I opted to install remove all packages that started with "tex..." and installed texlive-full.

Here are some screenshots of the problem:

Upon first load...

imagegen-error1.jpg

After pressing Ctrl + Shift + R...

imagegen-error1-after_refresh.jpg

And lastly, after one more Ctrl+Shift+R...

imagegen-error_gone.jpg

I screenshotted from different problems---forgive me---but the error relents no matter which problem I look at (provided that it is WW's first attempt at displaying the problem).


For the record, I also had issues with Library2 unable to add problems to a homework set. I enabled Library1 and was able to get around that issue.

Oh, I don't think there are issues with permissions. I followed the 2.7 Ubuntu manual very closely, although I didn't name my root user 'wwadmin'. Here is a screenshot of a relevant ls:

ww2-permissions.jpgPlease let me know if any more screenshots would be helpful!

I am running Ubuntu 12.04 64bit on an OpenVZ (I think) VPS. School starts on Monday... please help!

Thank you..

WeBWorK Main Forum -> Optimizing server settings for webwork

by Tony Box -
Hi All,

What are some good ways to improve the performance of the webserver that's running Webwork? Last semester, we were running into serious issues where students would take a quiz, try to submit an answer, and the page would hang. They'd have to refresh the page or hit the browser back button and re-submit the answer multiple times to try and get it to submit. This would occur at seemingly random times throughout the day, but mostly at night or very early in the morning (2am).

I've since updated to the newest version of Webwork in hopes that it would improve the performance. I just had a report from a faculty member who said that Webwork was acting up again.

For the old server, we threw a crap ton of memory and processors on it and still encountered the issue so it's clearly not an underpowered issue. What types of things should I look for on the server that might cause the pages to hang when loading?

I know this is a pretty broad question, but any help is most appreciated.

Thanks,
Tony
Hi Nathaniel,

Your students will not experience the problem you are having. When your students open a homework problem, they will see graphs that are generated specifically for them using their random seed. The images that are generated will be cached on the server, and using $refreshCachedImages = 0; means that the cached image will be used for the student (this is the default, I think). Using $refreshCachedImages = 1; means that every time the student accesses that question, a new image will be generated and delivered to the student so that the cached version is never used.

The reason this problem arises when viewing problems in the homework sets editor or the library browser is that old cached versions of the images are being used. I am pretty sure that this bug has been on our radar for a while, but perhaps has not been a high enough priority to get fixed yet. In the future, we may want to circumvent this problem by switching from cached GIF files to dynamically generated and delivered SVG files (which Bill Wheeler already has done at Indiana U) or a similar HTML5 solution.

Best regards,

Paul Pearson
One of the (few) aspects I like about MyMathLab is that it allows students unlimited attempts at a complete set of questions: but every time they have to start again from scratch. This prevents a student from hammering away at a single question putting in values on a trial-and-error basis until they get something that works.

Does WeBWork provide similar functionality - a student can attempt a given set of questions unlimited times, but each time the entire question set is refreshed anew?

Thanks,
Alasdair

WeBWorK Main Forum -> MathJax display issues with IE

by Tim Flowers -
We have a local WeBWorK server and I have MathJax as the default display style in all of our courses. I have been getting reports from instructors and students about problems not displaying correctly. Only "[math]" displays the first time a problem opens. This appears to only happen with Internet Explorer.

It usually goes away 2-3 clicks of the refresh button. And I know that changing to "images" will bypass the problem.

I have never had this issue in Firefox, Safari, etc. (I never use IE). Any reason why this would happen with IE only?