SMath Studio Forum
»
SMath Studio
»
Questions
»
Rounding Values in Vectors - User Function
Rank: Advanced Member Groups: Registered
Joined: 02/04/2018(UTC) Posts: 135 Was thanked: 22 time(s) in 19 post(s)
|
Version: 0.99 (Build: 7921) The rounding function concept for a vector seems to work fine, but I am having trouble with a function that works on a vector containing multiple vectors. Any ideas on how to make this work? Rounding Values in Vectors Function Concepts.sm (18kb) downloaded 12 time(s).Edited by user 26 April 2022 00:31:32(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 23/07/2013(UTC) Posts: 1,129 Was thanked: 510 time(s) in 340 post(s)
|
Originally Posted by: wb.c The rounding function concept for a vector seems to work fine, but I am having trouble with a function that works on a vector containing multiple vectors. Any ideas on how to make this work? You can use recursive for that. You have to also check if rounded row is a vector. It can work with both vector and nested vector. Here is your code revised. Regards PS: MarB's solution with Razonar's addition is better actually. I would use that instead of mine, more elegant. My version is just a brute algorithm. Rounding Values in Vectors Function Concepts.sm (24kb) downloaded 2 time(s). rounding_matrices.sm (11kb) downloaded 21 time(s).Edited by user 22 April 2022 23:37:49(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 05/06/2014(UTC) Posts: 348 Location: Colombo Was thanked: 127 time(s) in 82 post(s)
|
Another approach |
Look within!... The secret is inside you. Best Regards Eng. NDTM Amarasekera - Sri Lanka |
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 05/06/2014(UTC) Posts: 348 Location: Colombo Was thanked: 127 time(s) in 82 post(s)
|
Above method will not work if the nested arrays are of different sizes. Following method will work for any nested array. |
Look within!... The secret is inside you. Best Regards Eng. NDTM Amarasekera - Sri Lanka |
1 user thanked ndtma for this useful post.
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 15/07/2010(UTC) Posts: 437 Location: Beer-Sheva Was thanked: 520 time(s) in 288 post(s)
|
Almost the same Variant.sm (9kb) downloaded 7 time(s).
|
2 users thanked Ber7 for this useful post.
|
on 21/04/2022(UTC), on 21/04/2022(UTC)
|
|
Rank: Advanced Member Groups: Registered
Joined: 23/07/2013(UTC) Posts: 1,129 Was thanked: 510 time(s) in 340 post(s)
|
Code revised to solve not just vectors but matrices too. Now very complicated matrices can be rounded. Regards PS: MarB's solution with Razonar's addition is better actually. I would use that instead of mine, more elegant. My version is just a brute algorithm. rounding_matrices.sm (11kb) downloaded 21 time(s).Edited by user 22 April 2022 23:38:21(UTC)
| Reason: Not specified
|
4 users thanked overlord for this useful post.
|
on 21/04/2022(UTC), on 21/04/2022(UTC), on 21/04/2022(UTC), on 22/04/2022(UTC)
|
|
Rank: Advanced Member Groups: Registered
Joined: 02/04/2018(UTC) Posts: 135 Was thanked: 22 time(s) in 19 post(s)
|
Great ideas everyone, thanks for the input and improvements.
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 15/07/2010(UTC) Posts: 437 Location: Beer-Sheva Was thanked: 520 time(s) in 288 post(s)
|
|
|
|
|
Rank: Guest
Groups: Registered
Joined: 04/07/2015(UTC) Posts: 6,866 Was thanked: 981 time(s) in 809 post(s)
|
Good idea to always start code native Smath ... given user extended.
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 23/07/2013(UTC) Posts: 1,129 Was thanked: 510 time(s) in 340 post(s)
|
You can also shorten function like this.
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 21/10/2016(UTC) Posts: 84
Was thanked: 21 time(s) in 17 post(s)
|
A very short way is to use recursion: roundM.sm (10kb) downloaded 7 time(s).Edited by user 22 April 2022 13:56:32(UTC)
| Reason: Not specified
|
4 users thanked MarB for this useful post.
|
on 22/04/2022(UTC), on 22/04/2022(UTC), on 22/04/2022(UTC), on 22/04/2022(UTC)
|
|
Rank: Guest
Groups: Registered
Joined: 04/07/2015(UTC) Posts: 6,866 Was thanked: 981 time(s) in 809 post(s)
|
Up to this point, proposals round nested vectors. Dealing with big numbers is also available. 123456789123456789 ... 987654321987654321 123000000000000000 typical
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 23/07/2013(UTC) Posts: 1,129 Was thanked: 510 time(s) in 340 post(s)
|
Originally Posted by: MarB A very short way is to use recursion. This is just magnificent. Two heads are better than one. I couldn't hit off how to do it with vectorize. Kudos
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 15/07/2010(UTC) Posts: 437 Location: Beer-Sheva Was thanked: 520 time(s) in 288 post(s)
|
Originally Posted by: MarB A very short way is to use recursion:
Wonderful!
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 28/08/2014(UTC) Posts: 1,370 Was thanked: 829 time(s) in 525 post(s)
|
Originally Posted by: MarB A very short way is to use recursion ...
Brillant solution. Adding eval to the SMath's round enables symbolic evaluations too. Best regards. Alvaro.
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 15/04/2012(UTC) Posts: 1,990 Was thanked: 1128 time(s) in 724 post(s)
|
|
|
2 users thanked mkraska for this useful post.
|
on 23/04/2022(UTC), on 23/04/2022(UTC)
|
|
Rank: Guest
Groups: Registered
Joined: 04/07/2015(UTC) Posts: 6,866 Was thanked: 981 time(s) in 809 post(s)
|
... twin vectors from function Advanced Engineering applications.
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 23/07/2013(UTC) Posts: 1,129 Was thanked: 510 time(s) in 340 post(s)
|
Originally Posted by: mkraska Minimalistic solution for Maximalists. Sometimes I really wish I could use Maxima plugin under linux.
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 15/04/2012(UTC) Posts: 1,990 Was thanked: 1128 time(s) in 724 post(s)
|
Originally Posted by: overlord Originally Posted by: mkraska Minimalistic solution for Maximalists. Sometimes I really wish I could use Maxima plugin under linux. It is on my todo list and I think it is possible, but currently priority is on another project which also involves using Maxima and is entirely open source: https://github.com/mkraska/meclib |
|
|
|
|
SMath Studio Forum
»
SMath Studio
»
Questions
»
Rounding Values in Vectors - User Function
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.