Count number usage

I am trying to adapt a code from a colleague’s activity to a new activity but I can’t get the table to recognize a correct answer. I am pretty sure my error is in using countnumberusage. Can someone guide me on this?

1 Like

Your > and < are backwards.

1 Like

Thanks! I fixed that and now it only counts the first one as correct. Still not recognizing all the other ones.

1 Like

Apparently, simpleFunction is more stable than numericValue, so I tried this and it works:

check2=simpleFunction("\sqrt{512}").evaluateAt(0)=
 simpleFunction("${table1.cellNumericValue(2,2)}").evaluateAt(0) and 
countNumberUsage(a2,16)=1 and countNumberUsage(a2,22)=0 and 
countNumberUsage(a2,7)=0 
1 Like

Thanks! Will that also work for sqrt(-98)? Or will I need a different type of argument because of the i?

1 Like

You could do something like:

check2=simpleFunction("\sqrt{98i}","i").evaluateAt(2)=
 simpleFunction("${table1.cellNumericValue(2,2)}","i").evaluateAt(2) and 
countNumberUsage(a2,7)=1 and countNumberUsage(a2,2)=1
1 Like

So I still don’t know what I am doing wrong. Here is the activity again. I have fixed the first 5 on slide 8 and I will be honest, I am having the same issue on slide 9.

1 Like

Your evaluations for a3 are not right.
For f(i)=-10+23i,
f(1)=13
f(2)=36

It will also be easier to compare simpleFunction to simpleFunction (which should work for your answers with radicals as well instead of using < and > comparisons). I made a few adjustments (like fa3 is the function for a3, and exp3 the function for the expected answer):

#(4+i)(-1+6i)=-10+23i
a3=table2.cellContent(3,2)
fa3= simpleFunction(a3,"i")
exp3=simpleFunction("-10+23i","i")
check3=fa3.evaluateAt(1)=exp3.evaluateAt(1) and fa3.evaluateAt(2)=exp3.evaluateAt(2) 
     and fa3.evaluateAt(3)=exp3.evaluateAt(3) 
     and countNumberUsage(a3,10)=1 and countNumberUsage(a3,23)=1
answer3 =
  when check3 1
  otherwise 0
1 Like

Count number usage is not my friend. I struggle with it every time I try to use it. Can you tell me why it isn’t working on slide 3 of this activity?

1 Like

I don’t see anything wrong with your code. I think the issue is the function notation in the initial latex. When I deleted that part, it was marked as correct. If you want to include that notation, you might be able to parse the left side of the equation and use pattern matching to get this to work.

1 Like

I actually don’t think the issue is with countNumberUsage. I’m pretty sure simpleFunction only works with “y=” or “f(x)=” (or other letter besides f). I changed to this and it worked:

check1= simpleFunction(parseEquation(exp1.latex).rhs).evaluateAt(0)=-2 and 
simpleFunction(parseEquation(exp1.latex).rhs).evaluateAt(1)=2 and 
simpleFunction(parseEquation(exp1.latex).rhs).evaluateAt(-1)=-2 and 
countNumberUsage(exp1.latex,6)=0 and countNumberUsage(exp1.latex,5)=0
1 Like