As a test, I increased the value n (iterations) and that forced it to
converge on the value 150999.

Sounds like I need a test of convergence.

On Sun, 1 May 2022 at 08:37, Lester Anderson <arctica1...@gmail.com> wrote:

> Having an issue with the code:
>
> Tried: x ≡ 2 mod 11; 3 mod 12; 4 mod 13; 5 mod 17; 6 mod 19 (result should
> be 150999 but get 442719)
> Also checked x ≡ 4 mod 11; 3 mod 17 (result should be 37 but get 136)
> However, 3 equations work fine!
>
> I have pinned down the problem to M_inv, where it is not looping through
> all elements (m) but doing one less (eg 4 instead of 5).
>
> for i=1:length(m)
>     for j=1:n
>         if modulo(((M_ratio(i)*j)-1),m(i)) == 0
>         M_inv(i)=j;
>         xn(i)=(a(i)*M_ratio(i)*M_inv(i));
>         end
>     endend
>
> With the code snippet above, it should iterate 5 times for 5 input values of 
> a and m, it is not generating M_inv(5), or M_inv(2) (2 equations).
>
> I have verified what the results should be in Maxima CAS,
>
> [image: image.png]
>
> Any ideas what is going wrong?
>
> Thanks
>
> On Sun, 1 May 2022 at 05:32, Lester Anderson <arctica1...@gmail.com>
> wrote:
>
>> Many thanks Samuel
>>
>> On Sat, 30 Apr 2022 at 17:28, Samuel Gougeon <sgoug...@free.fr> wrote:
>>
>>> Le 30/04/2022 à 18:26, Samuel Gougeon a écrit :
>>>
>>> Le 30/04/2022 à 18:14, Lester Anderson a écrit :
>>>
>>> Sorted the code with multiple equations. Not too sure how to deal with
>>> the messagebox list of equations.
>>> Still have to do that manually - unless there is a way to automatically
>>> build this?
>>>
>>> Can this multiple text string be done via a for loop to build a list ?
>>>
>>> Thanks
>>>
>>>
>>> Please \n as trailer for the 2nd msprintf as well:
>>>
>>> [ msprintf("x ≡ %d  mod %d\n", a(:), m(:))
>>>    msprintf("The solution for (x): %d mod %d\n", x(:), M(:))
>>>                     'Solution of 3 congruence equations']
>>>
>>>
>>>
_______________________________________________
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

Reply via email to