Operation of vector elements

Operation of vector elements - assign values to vector elements with for loop? - Сообщения

#1 Опубликовано: 08.03.2019 03:11:59
RegCurry

RegCurry

0 сообщений из 57 понравились пользователям.

Группа: User

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.
#2 Опубликовано: 08.03.2019 03:48:51
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1674 понравились пользователям.

Группа: User

Hi. Something like this?

vector.sm (6 КиБ) скачан 35 раз(а).

Clipboard01.jpg

Best regards.
Alvaro.
#3 Опубликовано: 08.03.2019 04:34:04
RegCurry

RegCurry

0 сообщений из 57 понравились пользователям.

Группа: User

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.
#4 Опубликовано: 08.03.2019 04:42:19
RegCurry

RegCurry

0 сообщений из 57 понравились пользователям.

Группа: User

Here is a better image.Test.jpg
#5 Опубликовано: 08.03.2019 04:50:14
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1674 понравились пользователям.

Группа: User

This?

vector.sm (4 КиБ) скачан 35 раз(а).

Clipboard01.jpg

Best regards.
Alvaro.
#6 Опубликовано: 08.03.2019 04:54:10
RegCurry

RegCurry

0 сообщений из 57 понравились пользователям.

Группа: User

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

Thanks again!
#7 Опубликовано: 08.03.2019 04:57:58
RegCurry

RegCurry

0 сообщений из 57 понравились пользователям.

Группа: User

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.
#8 Опубликовано: 08.03.2019 04:58:28
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1674 понравились пользователям.

Группа: User

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 (7 КиБ) скачан 36 раз(а).

Clipboard01.jpg

Best regards.
Alvaro.
1 пользователям понравился этот пост
frapuano 08.03.2019 05:05:00
#9 Опубликовано: 08.03.2019 05:50:19
RegCurry

RegCurry

0 сообщений из 57 понравились пользователям.

Группа: User

Interesting; thanks for that also.

#10 Опубликовано: 08.03.2019 10:15:09
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

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 (21 КиБ) скачан 40 раз(а).
#11 Опубликовано: 08.03.2019 11:18:10
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

Is it possible to assign specific values to specific elements


... more matrix utilities

Utilities Matrix Treasury_1.sm (394 КиБ) скачан 46 раз(а).

#12 Опубликовано: 08.03.2019 12:10:27
Martin Kraska

Martin Kraska

1222 сообщений из 2150 понравились пользователям.

Группа: Moderator

vector(1).png
vector(1).sm (3 КиБ) скачан 50 раз(а).
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
3 пользователям понравился этот пост
sergio 08.03.2019 12:47:00, NDTM Amarasekera 08.03.2019 13:12:00, frapuano 08.03.2019 18:02:00
#13 Опубликовано: 08.03.2019 14:22:13
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

... 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 (20 КиБ) скачан 74 раз(а).
#14 Опубликовано: 09.03.2019 02:19:10
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

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.

  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений