Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline RegCurry  
#1 Posted : 08 March 2019 09:11:59(UTC)
RegCurry


Rank: Advanced Member

Groups: Registered
Joined: 10/02/2019(UTC)
Posts: 56
Man
United States
Location: Colorado

Is it possible to assign specific values to specific elements and take the absolute value of other specific elements of a large vector with say 400 elements? I have tried for loops and if structure to no avail. I assume I just still don't understand the syntax in SMath.

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Razonar  
#2 Posted : 08 March 2019 09:48:51(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,367
Uruguay

Was thanked: 826 time(s) in 523 post(s)
Hi. Something like this?

vector.sm (7kb) downloaded 15 time(s).

Clipboard01.jpg

Best regards.
Alvaro.
Offline RegCurry  
#3 Posted : 08 March 2019 10:34:04(UTC)
RegCurry


Rank: Advanced Member

Groups: Registered
Joined: 10/02/2019(UTC)
Posts: 56
Man
United States
Location: Colorado

Thanks for your help.
What if I don’t know the positions that need changing ahead of time? In my vector of about 400 elements, some values are negative. I would like to change only those values to about 10^-10 or take their absolute value and leave all the other elements of the vector unchanged because I plan to plot the vector on a log-log plot.

This is quite easy to do in Mathcad, but it seems SMath doesn’t have the same capability. When I try to test on a value of an element using SMath’s if statement to see if that vector element needs changing I get syntax errors in SMath.

I was hoping to use something like this, but it doesn’t work.


k := [1...length(I)]

A[k := if I[k<= 0
10^-10
else
I[k


Where I is the vector of about 400 elements

Forgive the [ since the forum doesn’t allow subcripts or less than or equal. I am on my iPad now and the forum also does not allow uploading jpg from my photos.
Offline RegCurry  
#4 Posted : 08 March 2019 10:42:19(UTC)
RegCurry


Rank: Advanced Member

Groups: Registered
Joined: 10/02/2019(UTC)
Posts: 56
Man
United States
Location: Colorado

Here is a better image.Test.jpg
Offline Razonar  
#5 Posted : 08 March 2019 10:50:14(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,367
Uruguay

Was thanked: 826 time(s) in 523 post(s)
This?

vector.sm (5kb) downloaded 13 time(s).

Clipboard01.jpg

Best regards.
Alvaro.
Offline RegCurry  
#6 Posted : 08 March 2019 10:54:10(UTC)
RegCurry


Rank: Advanced Member

Groups: Registered
Joined: 10/02/2019(UTC)
Posts: 56
Man
United States
Location: Colorado

Thanks much. I thought I tried that in using a program line, but I guess I had some typo.

Thanks again! Clap
Offline RegCurry  
#7 Posted : 08 March 2019 10:57:58(UTC)
RegCurry


Rank: Advanced Member

Groups: Registered
Joined: 10/02/2019(UTC)
Posts: 56
Man
United States
Location: Colorado

I tried to click on thank for you, but I got an error. Perhaps the forum doesn’t like iPads.

Again I really appreciate your help.
Offline Razonar  
#8 Posted : 08 March 2019 10:58:28(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,367
Uruguay

Was thanked: 826 time(s) in 523 post(s)
Hi. The method in your picture, using range vectors, fails because 'if' have an special evaluation method, For instance, the true or false parts are evaluated only if the condition results in true or false, respectively.

This method is a workaround, but isn't very efficient.

vector.sm (8kb) downloaded 16 time(s).

Clipboard01.jpg

Best regards.
Alvaro.
thanks 1 user thanked Razonar for this useful post.
on 08/03/2019(UTC)
Offline RegCurry  
#9 Posted : 08 March 2019 11:50:19(UTC)
RegCurry


Rank: Advanced Member

Groups: Registered
Joined: 10/02/2019(UTC)
Posts: 56
Man
United States
Location: Colorado

Interesting; thanks for that also.

Offline Jean Giraud  
#10 Posted : 08 March 2019 16:15:09(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: RegCurry Go to Quoted Post
Is it possible to assign specific values to specific elements

The attached is not exactly what you are looking for,
suggestive of Bolean Find-Replace in matrix.

Your 400 long vector is not easy to inspect, you can Pack in matrix,
probably Find-Replace in that more visible Packed matrix, then
Unwrap the processed matrix back in vector.
IMHO, it does not make much sense to |absolute| a vector.
Does it mean the vector-creator is under-designed ?
Matrices-Vectors ... what you do in Mathcad, Smath does.
Easy to select-collect position of elements in vector,
then replace those selected elements by new values.
You seem to have several demands to the "Cat in the hat Fairy",
Maybe she has all and +++

Cheers ... Jean

Utilities Matrix Find_Replace.sm (22kb) downloaded 15 time(s).
Offline Jean Giraud  
#11 Posted : 08 March 2019 17:18:10(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: RegCurry Go to Quoted Post
Is it possible to assign specific values to specific elements

... more matrix utilities

Utilities Matrix Treasury_1.sm (395kb) downloaded 23 time(s).

Offline mkraska  
#12 Posted : 08 March 2019 18:10:27(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,989
Germany

Was thanked: 1128 time(s) in 724 post(s)
vector(1).png
vector(1).sm (4kb) downloaded 28 time(s).
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
thanks 3 users thanked mkraska for this useful post.
on 08/03/2019(UTC),  on 08/03/2019(UTC),  on 09/03/2019(UTC)
Offline Jean Giraud  
#13 Posted : 08 March 2019 20:22:13(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
... more stuff,
Easy to replace part of a vector or of a specified matrix-col
by a user vector at specified position.

Utilities Matrix Replace_in_Vector.sm (21kb) downloaded 40 time(s).
Offline Jean Giraud  
#14 Posted : 09 March 2019 08:19:10(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: RegCurry Go to Quoted Post
In my vector of about 400 elements, some values are negative.I would like to change only those values to about 10^-10 or take their absolute value and leave all the other elements of the vector unchanged because I plan to plot the vector on a log-log plot.

Reg: that's what we need the 400 long vector.
Supplementary instructions/abstract guidance too.

Users browsing this topic
Guest
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.