<div dir="ltr">Having an issue with the code:<div><br></div><div>Tried: x ≡ 2 mod 11; 3 mod 12; 4 mod 13; 5 mod 17; 6 mod 19 (result should be 150999 but get 442719)</div><div>Also checked x ≡ 4 mod 11; 3 mod 17 (result should be 37 but get 136)</div><div>However, 3 equations work fine!</div><div><span style="font-family:Arial;color:rgb(160,32,240)"><br></span></div>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).<div><pre style="font-family:Arial"><span style="color:rgb(160,32,240)">for</span> <span style="color:rgb(0,0,0)">i</span><span style="color:rgb(92,92,92)">=</span><span style="color:rgb(188,143,143)">1</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(50,185,185)">length</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">m</span><span style="color:rgb(74,85,219)">)</span>
<span style="color:rgb(160,32,240)">for</span> <span style="color:rgb(0,0,0)">j</span><span style="color:rgb(92,92,92)">=</span><span style="color:rgb(188,143,143)">1</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">n</span>
<span style="color:rgb(160,32,240)">if</span> <span style="color:rgb(174,92,176);text-decoration-line:underline">modulo</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">M_ratio</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">*</span><span style="color:rgb(0,0,0)">j</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">-</span><span style="color:rgb(188,143,143)">1</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">m</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(92,92,92)">==</span> <span style="color:rgb(188,143,143)">0</span>
<span style="color:rgb(0,0,0)">M_inv</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">=</span><span style="color:rgb(0,0,0)">j</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(0,0,0)">xn</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">=</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">a</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">*</span><span style="color:rgb(0,0,0)">M_ratio</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">*</span><span style="color:rgb(0,0,0)">M_inv</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
<span style="color:rgb(160,32,240)">end</span>
<span style="color:rgb(160,32,240)">end</span>
<span style="color:rgb(160,32,240)">end</span></pre></div><pre style="font-family:Arial">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). </pre><pre style="font-family:Arial">I have verified what the results should be in Maxima CAS, </pre><img src="cid:ii_l2myu53n0" alt="image.png" width="347" height="69"><br><div><br></div><div>Any ideas what is going wrong?</div><div><br></div><div>Thanks</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 1 May 2022 at 05:32, Lester Anderson <<a href="mailto:arctica1963@gmail.com">arctica1963@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Many thanks Samuel</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 30 Apr 2022 at 17:28, Samuel Gougeon <<a href="mailto:sgougeon@free.fr" target="_blank">sgougeon@free.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div>Le 30/04/2022 à 18:26, Samuel Gougeon a
écrit :<br>
</div>
<blockquote type="cite">
<div>Le 30/04/2022 à 18:14, Lester
Anderson a écrit :<br>
</div>
<blockquote type="cite">
<div dir="ltr">Sorted the code with multiple equations. Not too
sure how to deal with the messagebox list of equations.
<div>Still have to do that manually - unless there is a way to
automatically build this?</div>
<div><br>
</div>
<div>Can this multiple text string be done via a for loop
to build a list ?</div>
<div><br>
</div>
<div>Thanks</div>
</div>
</blockquote>
<br>
</blockquote>
Please \n as trailer for the 2nd msprintf as well:<br>
<blockquote type="cite">
<pre style="font-family:Arial"><span style="color:rgb(74,85,219)"></span>[ msprintf(<span style="color:rgb(188,143,143)">"</span><span style="color:rgb(188,143,143)">x ≡ %d</span><span style="color:rgb(188,143,143)"></span><span style="color:rgb(188,143,143)"> mod %d\n", </span><span style="color:rgb(188,143,143)"></span><span style="color:rgb(92,92,92)"></span><span style="color:rgb(50,185,185)"></span><span style="color:rgb(74,85,219)"></span><span style="color:rgb(0,0,0)">a(:), m(:))</span><span style="color:rgb(255,170,0)"></span>
msprintf(<span style="color:rgb(188,143,143)">"</span><span style="color:rgb(188,143,143)">The solution for (x): </span><span style="color:rgb(188,143,143)">%d mod </span><span style="color:rgb(188,143,143)">%d<font color="#ff0000">\n</font>"</span>, x(:), M(:))
<span style="color:rgb(188,143,143)">'</span><span style="color:rgb(188,143,143)">Solution of 3 congruence equations</span><span style="color:rgb(188,143,143)">'<font color="#000000">]</font></span></pre>
</blockquote>
<br>
</div>
</blockquote></div>
</blockquote></div>