Karim Belabas on Thu, 21 Mar 2024 18:13:47 +0100
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Error in pari/gp code
|
- To: "Swati, NoFirstName" <S10@email.sc.edu>
- Subject: Re: Error in pari/gp code
- From: Karim Belabas <Karim.Belabas@math.u-bordeaux.fr>
- Date: Thu, 21 Mar 2024 18:13:41 +0100
- Arc-authentication-results: i=1; smail; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1711041222; c=relaxed/relaxed; bh=il1LceldZusnmuPA4WQ6EXInt2DP0U4IY8EJfP+e13k=; h=DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: Mail-Followup-To:References:MIME-Version:Content-Type: Content-Disposition:Content-Transfer-Encoding:In-Reply-To; b=Ah5HrHqt3GlH7/ZxMNHjHQ72X69nh7eLCIzMk9VVBYlcUyE+O8XV2Mvfp4WkE46HraH23DVFmfCLq5NOWYCuekWFMwpeL+ZG7gKpmJZivA6IO4oVwOC741G3zvupI8hfTR3jkZItGUCgJJF4ZNnG8HWiowVH2gVPWzaaUyaaUFHFM3y5Wua9+kC/FXqZz5r7nYSXT9gK2e6wbyzAyAxa6kAYXxs7cRzQctR0DjdOgD6ezbOjAzglYZ/as90KxneD6yxnSDz6HbuoDuHvfcGe1hQHw7srdSfWT5j6LUNSiRxRYzSuuheB7zFMsZqLG2NoygPJn1AcKTifWSfly855TOfm3ohHWInQMONETzOsN4PAsXUeaM86MCNmCx8OeLAKklHoBEUNArZRjPNz38CX34qeeBonv1lSFPKcsqaqmUbfk2t43zqMEmpaw3QXMf28RMf4rHhWHy83ZYQ7cSbbUgJ700O6/wzWWzQFoBZ0sYuodtoPbW9IZdYXmZYLLeRJUoZRKpCuLpXdvlBxEXxGxPGIA/hNWn/+4xFkWGDsPPKWzNyrxUgXeOuvJMgggpiYyVPXcOyux+QAxVv7cPd5HRalsODUwUJr25rzEPF1sxq5vDTBpqWtoAKoDm+1bW2zSAoNW07L6cQAH4+Cu7JJ42s3v4t98OuYyZJw7c+csVs=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1711041222; cv=none; b=TxiHKrir18bLHIMvqPlzFlJR69XQWpgFykTl5bl6jx/GfuHaorEeyIEBbxY45e5ZiN8LKblKgm8VyB63a8z/cz4JKRwHZEVQDj86KV/+89URGjGFKmsNmDd9OKZR7cpO8wlmwyPedD4KAqQ98pv3mFdw2GXeI8Rl5gO25nwC4TkeeeRIQ6QE7ggyr3JTPRYnA0shbd9C0lAqGV9j5QT4/1SdHeQY0HWdzXTUPIccGx/ZFjhVrfKPDWBlgARiQBvVWm5I8088b+inBTi6SWn83SeqRphc25aIMo+Tnl+GYQp2zL6QLgEd+WWrq6ClszFVTKrRJCnWtwEPEjmMk3ynRCgKWPXCGW5r0qhVcM5B2YQGC7ShQtVPxHyV7SEMlc8fJCZ+xRHNnpnksY8nbG5r9aUOpiIFTeC/VeFZ1Ia11OroYjIIqdWaK7TF/rZHq/KJ2ETJHT9AKDPIj5gmXrUb2LsMTGiVlLFDyc0U4lSYOTRQIFHVzZxjMvzt7u+64j22Jo0cWV1xYf3vtuxS2rMm/ehHF0LN9FDqddEccvID4VluXETl0POeJCGT+hxiY80/+/MhdH7mgUhPBTncjUKFYoORuI9WcHMR6g9fQNp66SFuqwf7PMy5barUiu7Mum4vFwdj29mcQOesvPaRvxs0qvZRcXLu7mBtPt+UL9OXBnA=
- Authentication-results: smail; dmarc=none header.from=math.u-bordeaux.fr
- Authentication-results: smail; arc=none
- Cc: "pari-users@pari.math.u-bordeaux.fr" <pari-users@pari.math.u-bordeaux.fr>
- Delivery-date: Thu, 21 Mar 2024 18:13:47 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1711041222; bh=il1LceldZusnmuPA4WQ6EXInt2DP0U4IY8EJfP+e13k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=o2dztXiMCql7AbM7AaYtq7GW0pa9q+u7O2paQOfplWhHgh4VhP+JxqmS9wqDOUF/u Z/OVwk8C/v9u3h+zV1A+bpmRwx/79I/cDBlROuj2SFwF6+zzfwHwb1SvrBAjaAD+40 3Flx//tGF5l7UkMTJ6evS8Ukgo/PNp4l9K61qsbHHdV80lbS3+vdjxCG9Kho31QMKB BW+E5qwqRuFjws/sGVSDihr7Uz/PLdcSDA64ON4MwGSHZs9DuppeFzWU3zLhZZLoj2 zTigeb7ZIIi16tKXYc6eQraNQB122P+lUUKX6mSrsl6Ru7SIKzVOdsvVRHyuCyUHEy JK0IDoh/Rmsunz02/KlyU/Yc0n26lGYba0TDZO3nzPtPpvuJoiY2l9DdzLm7FnxLdl 8OWAj5p4DGdGCmX/UalgVccx4B+dQyOP1YupNWiECTC7sfTqMgtyphGrQdZ/UWmP4z RiSXPi0Ibtk+hFds4/bUQ2jqKki+BPu7M79oI2N/zUNf9TFTC34hfzkp2W5KULxiDu Jbgcg6F46gR5nOnpDC5vqrsLD1QnvBWANntvIM029H3KXn49fJ9ai3k4qTE4Oexbbf XysRfHhMi1IurLqL24zye61c+tel80ezEXCdjdk0MByHMapftjXlhBaMAkYHZBFmou cX43B/TthPQG1DpDJ33o0dBA=
- In-reply-to: <SJ0PR19MB47624346414FB65AD33305BF80322@SJ0PR19MB4762.namprd19.prod.outlook.com>
- Mail-followup-to: "Swati, NoFirstName" <S10@email.sc.edu>, "pari-users@pari.math.u-bordeaux.fr" <pari-users@pari.math.u-bordeaux.fr>
- References: <SJ0PR19MB47624346414FB65AD33305BF80322@SJ0PR19MB4762.namprd19.prod.outlook.com>
* Swati, NoFirstName [2024-03-21 17:10]:
> Hi,
> I am trying to write a code to output the position of the last non-zero entry of this matrix but the code is giving a syntax error. I am not sure what went wrong. Could someone help in this regard?
>
> Thanks,
> Swati
>
> C = [[1, 2, 3, 4], [7, 9, 10], [25, 31, 0], [0, 0, 0]];
> A = matconcat([C[1]; C[2]; C[3]; C[4]]);
>
> R = 0;
> C = 0;
> S= 0;
>
> for(i = matsize(A)[1], i >= 1 && S == 0, i--,
> for(j = matsize(A)[2], j >= 1 && S== 0, j--,
> if(A[i, j] != 0,
> R = i;
> C = j;
> S = 1;
> break;
> )))
>
> if(S == 1,
> print("Position of the last non-zero entry:" [R, C]),
> print("Matrix A contains only zeros.")
> );
>
Here's a corrected version
{
my (R = 0, C = 0);
forstep(i = matsize(A)[1], 1, -1,
forstep(j = matsize(A)[2], 1, -1,
if(A[i, j] != 0, R = i; C = j; break(2))));
if (R,
print("Position of the last non-zero entry: ", [R, C])
,
print("Matrix A contains only zeros."));
}
Position of the last non-zero entry: [3, 2]
Cheers,
K.B.
--
Pr. Karim Belabas, U. Bordeaux, Vice-président en charge du Numérique
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/