Rounding Values in Vectors - User Function

Rounding Values in Vectors - User Function - Trying to make a function that rounds values in vectors - Messages

#1 Posted: 4/21/2022 2:07:51 PM
Wesly Centerwall

Wesly Centerwall

26 likes in 156 posts.

Group: User

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?

2022-04-21 13_02_27-SMath Solver - [Rounding Values in Vectors Function Concepts.sm_].png
2022-04-21 13_03_06-SMath Solver - [Rounding Values in Vectors Function Concepts.sm_].png

Rounding Values in Vectors Function Concepts.sm (17 KiB) downloaded 30 time(s).
#2 Posted: 4/21/2022 2:35:30 PM
overlord

overlord

549 likes in 1332 posts.

Group: Moderator

Wrote

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 (23 KiB) downloaded 19 time(s).

rounding_matrices.sm (10 KiB) downloaded 37 time(s).

Click to enlarge
#3 Posted: 4/21/2022 2:40:42 PM
NDTM Amarasekera

NDTM Amarasekera

130 likes in 352 posts.

Group: User

Another approach

round_matrix.jpg
Look within!... The secret is inside you. Best Regards Eng. NDTM Amarasekera - Sri Lanka
#4 Posted: 4/21/2022 2:58:17 PM
NDTM Amarasekera

NDTM Amarasekera

130 likes in 352 posts.

Group: User

Above method will not work if the nested arrays are of different sizes.
Following method will work for any nested array.

Round_diff_Arr_sizes.jpg
Look within!... The secret is inside you. Best Regards Eng. NDTM Amarasekera - Sri Lanka
1 users liked this post
Wesly Centerwall 4/21/2022 3:16:00 PM
#5 Posted: 4/21/2022 3:10:48 PM
Fridel Selitsky

Fridel Selitsky

520 likes in 451 posts.

Group: User

Almost the same
Variant.png
Variant.sm (8 KiB) downloaded 24 time(s).
2 users liked this post
NDTM Amarasekera 4/21/2022 3:41:00 PM, Wesly Centerwall 4/21/2022 3:16:00 PM
#6 Posted: 4/21/2022 3:13:35 PM
overlord

overlord

549 likes in 1332 posts.

Group: Moderator

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 (10 KiB) downloaded 37 time(s).

Click to enlarge
4 users liked this post
Wesly Centerwall 4/21/2022 3:16:00 PM, NDTM Amarasekera 4/21/2022 3:41:00 PM, sergio 4/21/2022 4:51:00 PM, Alvaro Diaz Falconi 4/22/2022 11:15:00 AM
#7 Posted: 4/21/2022 3:16:07 PM
Wesly Centerwall

Wesly Centerwall

26 likes in 156 posts.

Group: User

Great ideas everyone, thanks for the input and improvements.
#8 Posted: 4/21/2022 5:42:27 PM
Fridel Selitsky

Fridel Selitsky

520 likes in 451 posts.

Group: User

Short code option
Variant1.png
Variant1.sm (5 KiB) downloaded 20 time(s).
#9 Posted: 4/21/2022 7:38:00 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Good idea to always start code native Smath ... given user extended.

Round matrix.PNG
#10 Posted: 4/21/2022 7:44:19 PM
overlord

overlord

549 likes in 1332 posts.

Group: Moderator

You can also shorten function like this.

2022-04-22_01-43.png
#11 Posted: 4/22/2022 7:39:35 AM
Martin_B

Martin_B

21 likes in 84 posts.

Group: User

A very short way is to use recursion:

roundM.sm (9 KiB) downloaded 21 time(s).

roundM.png
4 users liked this post
sergio 4/22/2022 8:09:00 AM, Fridel Selitsky 4/22/2022 9:58:00 AM, Alvaro Diaz Falconi 4/22/2022 11:15:00 AM, overlord 4/22/2022 5:33:00 PM
#12 Posted: 4/22/2022 9:33:12 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Up to this point, proposals round nested vectors.
Dealing with big numbers is also available.
123456789123456789 ... 987654321987654321
123000000000000000 typical
#13 Posted: 4/22/2022 9:44:08 AM
overlord

overlord

549 likes in 1332 posts.

Group: Moderator

Wrote

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
#14 Posted: 4/22/2022 10:07:55 AM
Fridel Selitsky

Fridel Selitsky

520 likes in 451 posts.

Group: User

Wrote

A very short way is to use recursion:

Wonderful!

#15 Posted: 4/22/2022 11:29:14 AM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Wrote

A very short way is to use recursion ...



Brillant solution. Adding eval to the SMath's round enables symbolic evaluations too.

Clipboard01.jpg

Best regards.
Alvaro.

#16 Posted: 4/22/2022 5:35:17 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Minimalistic solution for Maximalists.

rounding_matrices_Maxima.png
rounding_matrices_Maxima.sm (4 KiB) downloaded 24 time(s).
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
2 users liked this post
NDTM Amarasekera 4/22/2022 11:46:00 PM, sergio 4/23/2022 5:16:00 AM
#17 Posted: 4/22/2022 7:36:17 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

... twin vectors from function
Advanced Engineering applications.

Round Vectors.PNG
#18 Posted: 4/22/2022 8:56:06 PM
overlord

overlord

549 likes in 1332 posts.

Group: Moderator

Wrote

Minimalistic solution for Maximalists.


Sometimes I really wish I could use Maxima plugin under linux.
#19 Posted: 4/23/2022 6:31:05 AM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Wrote

Wrote

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
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
  • New Posts New Posts
  • No New Posts No New Posts