Page 1 of 1

Math help wanted: Zeller congruence

Posted: Sun Mar 17, 2024 11:58 pm
by MJU20
I'm trying to get an ESP32 to calculate Zeller's congruence.

This calculates a number that represents the weekday for a certain date.
https://en.wikipedia.org/wiki/Zeller%27s_congruence

I have tried several methods for calculation but it doesn't always return the right number.
In this example I have variables (not shown) for the day, month and year.
If I calculate the Zeller number, it doesn't always work.

I have tried local variables (.val1 ... .val8) as integer, as float and so on.

What can I try next?
This is one of my latest versions where I tested the variables with Floats..
zeller1.jpg
zeller1.jpg (113.42 KiB) Viewed 394 times
Any suggestions?

Re: Math help wanted: Zeller congruence

Posted: Mon Mar 18, 2024 3:31 am
by chipfryer27
Hi

Sorry to be brief, it's stupid O' clock and I'm heading out soon.

Very interesting little project. I would break the calculation down into individual steps containing one action (calculation) and then step through your chart checking each result is as expected. This would hopefully allow you to see where things are going astray.

I do notice that in your post you are assigning .val4 = .val3 /4 then in the next line assigning it to (year / 100). Haven't got time to check if that's correct but initially looks suspect.

Regards

Re: Math help wanted: Zeller congruence

Posted: Mon Mar 18, 2024 10:09 am
by medelec35
Hello.
I have attached a Flowchart which is not Zeller congruence, but it does calculate the day of the week in any year from 1753 to 2699.
I don't know if it will be useful for you.

Re: Math help wanted: Zeller congruence

Posted: Mon Mar 18, 2024 10:44 pm
by MJU20
@Both: Thanks for your reaction!

@chipfryer27 the example is my "disassembled" version of the Zeller congruence.
I've tried it in one calculation but this returned not always a good result.
That is why I decided to make the calculation again but step-by-step.
I can not figure out why this sometimes returns a good and why sometimes a bad result.
Is it because I use the wrong settings for the variables?
But even with a Float this should return a good result...
Strange :-(

@medelec35 Thanks for the example.
You won't believe this but this was something I already started with.
But, this seemed a bit overkill for me :-)
I appreciate this, and maybe, if I can't the Zeller one to work, I will use this one.

Still I wonder why the Zeller doesn't work...
Any suggestions?

Re: Math help wanted: Zeller congruence

Posted: Mon Mar 18, 2024 11:15 pm
by medelec35
MJU20 wrote:
Mon Mar 18, 2024 10:44 pm
But, this seemed a bit overkill for me
The experessions are simplified compared to Zeller congruence in my eyes, but I have place one expression in their own clacluatio box so help you single step to see how it all works.

Of couse you don't need the function call, I added it for my benefit.
MJU20 wrote:
Mon Mar 18, 2024 10:44 pm
Still I wonder why the Zeller doesn't work...
Any suggestions?
I would try without floats.
You don't need floor as the equivalent of floor is just a variable e.g byte, int or uint.
For example if you had intA= 11 and intB = 4
Then result of intA/intB = 2
That is the floor of 2.75