## WeBWorK Main Forum

### Re: using webwork 2.8 with sagecell: problem with acceptance of tos

by Marc BUFFAT -
Number of replies: 0
HI Jason
i try another example using AskSage, but I got an error
|Matrices must have at least one entry at line 41 of (eval 14775)
line $ans = Matrix($reply->{'diff'});
apparently I cannot get the sage result using WEBWORK dictionary (hash perl)
here is the code (found in your github)


## Template for calling Sage from within a WebWork pg file
## BEGIN_DESCRIPTION
## Sample problem embedding Sage in WW
## END_DESCRIPTION

DOCUMENT();

"PGstandard.pl",
"MathObjects.pl",
);

###############################################
##
## pg initializations and regular WeBWorK code

Context("Matrix");
$SageCode1=<<END; def ff(): return choice([sin,cos,exp,ln,lambda x: x]) def combination(*args): return prod([choice(i) for i in args]) u,v=var('u v') def simple_expression(): return combination(range(1,10),[u,u^2],[v,v^2]) def random_expression(): return ff()(simple_expression())+ff()(simple_expression()) f(u,v)=(random_expression(),random_expression(),simple_expression()) WEBWORK['function']=f(u,v) WEBWORK['diff']=f.diff()(u,v) END # Sage$reply = AskSage($SageCode1,{seed=>$problemSeed, accepted_tos=>true});
$F = Formula($reply->{function});
$ans = Matrix($reply->{'diff'});
Find the total derivative $$Df$$ of $f(u,v)={F}$
\{ $ans->ans_array(50)\} END_TEXT Context()->normalStrings; ANS($ans->cmp());
Any Idea ? Marc