From WeBWorK_wiki
Revision as of 14:01, 1 February 2008 by Glarose (talk | contribs) (New page: <h2>Variables Other than x in Formulas: PG Code Snippet</h2> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>This code snippet shows the essential PG code to ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Variables Other than x in Formulas: PG Code Snippet

This code snippet shows the essential PG code to use variables other than x in formulas. Note that these are insertions, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.

Problem Techniques Index

PG problem file Explanation
$d = Compute("-16 t^2 + 5 t + 16");

We need make no changes to the documentation or initialization sections of the problem file. In the set-up section, we add the variable(s) (comma separated) that we need to the Context. If we want to exclude any existing variable(s), we can use are instead of add (e.g., Context()->variables->are(t=>"Real",z=>"Real");).

The height of an object thrown upwards with an 
initial speed of 5ft/s from a height of 16ft is: 

The text and answer sections of the file need not be changed.

ANS( $d->cmp() );


Problem Techniques Index