## WeBWorK Main Forum

### using scaffolding - requires PGML?

by Joel Trussell -
Number of replies: 4
I tried to use scaffolding with my usual BEGIN_TEXT.. END_TEXT coding with no success. I can't get the effects indicated by the webpage http://webwork.maa.org/wiki/Scaffold#.WBijYcn9g1A
I want to require the student to work the sections sequentially, the sections must be correct before going to the next section, they can remain open after the correct solution. The code below lets the student open and work on any section. I tried various alternatives - can_open => "first_incorrect", is_open => "first_incorrect" does not allow either section to open for the student.

Thanks

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

DOCUMENT();

"PGstandard.pl",
"MathObjects.pl",
"parserFunction.pl",
"scaffold.pl",
"PGcourse.pl",
);

TEXT(beginproblem());

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

Context("Complex");
Context()->flags->set(
tolerance => 0.01,
tolType => "absolute",
);
#Values in the text-- for debugging
#$z1=-2; #$z2=-3;
#$p1 = 0; #$p2 = -1;
# Solutions with the given values are : K_minZeta=0.3333 OS_minZeta=1.1762 Ts_minZeta=4 Tp_minZeta=4.4429 eramp =0.5
#This code will work when all poles and zeros are in the RHP, and the poles are closer to the origin than the zeros (i.e., poles have smaller magnitude). p1 is better to be assigned as zero. Note that the OS, Ts and Tp reported need to bereported using the equations provided in class assuming a good second order approximation.

$z1=-random(3,6,1); do {$z2 = -random(3,6,1);} until ($z2 !=$z1);
$p1 = 0;$p2 = -random(1,2,1);

$pi = pi;$SageCode1=<<END;
p1 = $p1; p2 =$p2;
z1 = $z1; z2 =$z2;

var('x')
f= (x-p1)*(x-p2)*(x-0.5*(z1+z2))-(x-z1)*(x-z2)*(x-0.5*(p1+p2))
Root = f.roots()
if Root[0][0] > min(p1,p2):
p_breakaway = Root[0][0]
p_breakin = Root[1][0]
else :
p_breakaway = Root[1][0]
p_breakin = Root[0][0]

xc = 0.5*(Root[0][0]+Root[1][0])
R = 0.5*(Root[1][0] - Root[0][0])
d = sqrt(xc*xc -R*R)
a = atan2(R,d)
I = ComplexDoubleElement(0,1)
p_minZeta = -cos(a)*d + sin(a)*d*I;
K_minZeta= abs((p_minZeta-p1)*(p_minZeta-p2)/((p_minZeta-z1)*(p_minZeta-z2)));
wn_minZeta = abs(p_minZeta);
zeta_minZeta = -real(p_minZeta)/wn_minZeta;
OS_minZeta = 100*exp(-zeta_minZeta*$pi/sqrt(1-zeta_minZeta*zeta_minZeta)); Tp_minZeta =$pi/(wn_minZeta*sqrt(1-zeta_minZeta*zeta_minZeta));
Ts_minZeta = 4/(zeta_minZeta*wn_minZeta);

WEBWORK['K_minZeta']=K_minZeta
WEBWORK['OS_minZeta']=OS_minZeta
WEBWORK['Ts_minZeta']=Ts_minZeta
WEBWORK['Tp_minZeta']=Tp_minZeta
END

$result = AskSage($SageCode1,{
accepted_tos=>true,
debug=>0,
});

$result =~ s/I/i/; # replace I by i for complex$result->{webwork}->{K_minZeta}=~s/e/E/g;
$result->{webwork}->{Tp_minZeta}=~s/e/E/g;$K_minZeta = Compute($result->{webwork}->{K_minZeta});$K_minZeta = 1*$K_minZeta;# to make the form of output a number instead of an expression$OS_minZeta = Compute($result->{webwork}->{OS_minZeta});$OS_minZeta = 1*$OS_minZeta;# to make the form of output a number instead of an expression$Ts_minZeta = Compute($result->{webwork}->{Ts_minZeta });$Ts_minZeta = 1*$Ts_minZeta; # to make the form of output a number instead of an expression$Tp_minZeta= Compute($result->{webwork}->{Tp_minZeta});$Tp_minZeta= 1*$Tp_minZeta; # to make the form of output a number instead of an expression$eramp = -$p2/$K_minZeta/(-$z1)/(-$z2);
#############################
# Main text

Context()->texStrings;
# The scaffold
Scaffold::Begin(can_open => "when_previous_correct",
is_open => "first_incorrect");
Section::Begin("Part 1: find K and overshoot");
BEGIN_TEXT
This problem is related to Problems 7.1 in the text. $BR \{image("HW_8_Fig_1.png",height=>120, width=>400)\}$BR
$PAR For the unity feedback system shown in the figure above, the transfer function is$BR
$G(s) = \frac{K(s- z1)(s-z2)}{ s(s-p2)}$,

$PAR Find the value of the gain, $$K$$,that will yield the minimum damping ratio. (Tolerance is 0.1)$BR
$$K =$$ \{ ans_rule(10)\} $BR Find the estimated percent overshoot for this gain. (Tolerance is 0.1)$BR
$$overshoot =$$ \{ ans_rule(10)\} $BR$PAR
END_TEXT
Section::End();

Section::Begin("Part 2: find Ts, Tp and $$e_{ramp}(\infty)$$");

BEGIN_TEXT
Because we allow a large tolerance for the previous part, we will use standard values for the answer to this part. Assume the values $$K = K_minZeta$$ and $$overshoot = OS_minZeta$$.
$PAR Find the settling time $$T_s$$ and peak time $$T_p$$ for this case. (Tolerance is 0.001)$BR
$$T_s =$$ \{ ans_rule(10)\} and $$T_p =$$ \{ ans_rule(10)\} $BR$PAR
Find the expected steady-state error for the unit ramp input for the case of minimum damping ratio. (Tolerance is 0.001)$BR $$e_{ramp}(\infty) =$$ \{ ans_rule(10)\}$BR

END_TEXT
Section::End();
Context()->normalStrings;

##############################

$showPartialCorrectAnswers = 1; ANS($K_minZeta -> cmp(tolType => 'absolute', tolerance => 0.1)); # number
ANS( $OS_minZeta -> cmp(tolType => 'absolute', tolerance => 0.1)); # number ANS($Ts_minZeta-> cmp(tolType => 'absolute', tolerance => 0.001)); # number
ANS( $Tp_minZeta-> cmp(tolType => 'absolute', tolerance => 0.001)); # number ANS($eramp-> cmp(tolType => 'absolute', tolerance => 0.001)); # number

Scaffold::End();
ENDDOCUMENT();

### Re: using scaffolding - requires PGML?

by Davide Cervone -
Your answer checkers for each section must come within the Section::Begin() and Section::End() calls, as in the examples in the documentation within the scaffold.pl file. Everything that goes with a section must be between those commands. If you put the answer checkers outside the section, that means those answers don't belong to any section, and so both your sections will be considered "complete" with no answers submitted.

### Re: using scaffolding - requires PGML?

by Joel Trussell -
Great! that does the trick. While the example shows the answer checkers inside, it would  help if that requirement would be mentioned in the documentation.
thanks

### Re: using scaffolding - requires PGML?

by Davide Cervone -

Within a section, use BEGIN_TEXT/END_TEXT or BEGIN_PGML/END_PGML to create the text of the section as usual, and ANS() to assign answer checkers to the blanks that appear within the section.

and

Whatever answer checkers are assigned within a section are the ones that are used to decide when that section can be opened by the student. ... A section is considered to be "correct" when all the answers contained in it are correct.

and

Note that you can also create text (or even answer blanks and checkers) between the sections, or before the first one, or after the last one, if you wish. That material would always be showing, regardless of which sections are open.

though perhaps it needs to be more explicit.

### Re: using scaffolding - requires PGML?

by Joel Trussell -
I mentioned using the online link
http://webwork.maa.org/wiki/Scaffold#.WBj2Dcn9g1A
which I thought was sufficient to start.

Now that you mention the descriptions, I searched and found
https://github.com/openwebwork/pg/blob/master/macros/scaffold.pl
which contains the text you quote.

I plead guilty to not going deep enough, and I thank you for indicating that I should actually read the macros before using them, which I rarely do.

thanks