Deprecated: Required parameter $errors follows optional parameter $type in /customers/5/9/f/padowan.dk/httpd.www/forum/include/parser.php on line 524

Topic: Calculating the remainder

What is the function for calculating a remainder in Graph? In coding languages it's a%b, but I didn't find it from the operator list. I would like to graph the attached function.

Post's attachments

Alkuluvut_kaava.png, 1.48 kb, 226 x 78
Alkuluvut_kaava.png 1.48 kb, 588 downloads since 2012-05-19 

Re: Calculating the remainder

It is called mod in Graph.Try this in the beta version of Graph 4.4:

f(x)=Sum(Mod(x,i)-mod(x-i,i)-(x-2), i, 1, x-1)

Re: Calculating the remainder

It gives an error 56 that says "Invalid number of arguments supplied for the function 'sum'". When I write both 'sum' and 'mod' with small letters, it gives me a graph. At this point I notice that the graph is different from what it should be. Turns out that you wrote the function wrong and it should be f(x)=sum(mod(x,i)-mod(x-i,i), i, 1, x-1)-(x-2). Now, however, it gives me just a straight line, which is not the function that I expected either. Then I saw that you read my function even worse and mod(x-i,i) should actually be mod(x-1,i). NOW it's right. big_smile Thank you!

Re: Calculating the remainder

Sorry about that. I am afrad I was a little too fast, and I wasn't home when answering so I couldn't test it with Graph. I am glad you figured it out.

Re: Calculating the remainder

No problem. You made my day with those mistakes big_smile

Re: Calculating the remainder

Btw, why is that function called mod? I'm familiar with mod calculations but I hate them in this kind of use. That's because here the result is always the smallest possible positive number, but in math mod has infinite amount of results and also negative ones. Mod 3: 5 can be 2 as it's here, but it can also be -4, -1, 8, 11, 14 and so on. I know there isn't many ways how to handle such calculations with graphing software and it's practical to expect the wanted result to be the smallest positive, but it kind of made me confused. smile

Re: Calculating the remainder

There is the condition applied for modulo function: abs(reminder) < abs(divisor). This condition allows only two results for a calculation, positive or negative value. For Graph, there is an answer in menu item Help-Contents-Functions-Special-mod function. More detailed description can be found in http://en.wikipedia.org/wiki/Modulo_operation .