String to Variable Name (str2var)

String to Variable Name (str2var) - 消息

#1 已发布: 2022/12/31 02:33:45
Mark R Harris

Mark R Harris

5个赞,共90个帖子。

组: User

Is there a function or method that would allow a string (or variable name) located in a matrix element to be used as the name to define a variable?

Something like this:

Str2Var.png

Thank you!
#2 已发布: 2022/12/31 04:28:45
Вячеслав Мезенцев

Вячеслав Мезенцев

1,558个赞,共1,868个帖子。

组: Moderator

未找到文件。 未找到文件。

str2num_full.png
Russia ☭ forever, Viacheslav N. Mezentsev
4位用户喜欢此帖子
Mark R Harris 2022/12/31 06:43:00, NDTM Amarasekera 2022/12/31 10:10:00, overlord 2023/1/1 15:20:00, sergio 2022/12/31 08:09:00
#3 已发布: 2022/12/31 06:43:07
Mark R Harris

Mark R Harris

5个赞,共90个帖子。

组: User

Thank you so much uni!
#4 已发布: 2023/1/1 12:51:50
Laurent Fournier

Laurent Fournier

9个赞,共66个帖子。

组: User

WOW!!!
#5 已发布: 2023/1/2 06:31:00
Martin Kraska

Martin Kraska

1,362个赞,共2,276个帖子。

组: Moderator

Wrote

Is there a function or method that would allow a string (or variable name) located in a matrix element to be used as the name to define a variable?



You can also use the Assign() function of the Maxima Plugin (this should work even without Maxima installed).

It converts boolean equations into assignments.

In the case of strings you still need to apply str2num()

Assign.sm (4.75 KiB)已下载 1353 次。
assign.PNG
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
2位用户喜欢此帖子
sergio 2023/1/2 07:35:00, Mark R Harris 2023/1/2 17:02:00
#6 已发布: 2023/1/4 20:02:47
Mark R Harris

Mark R Harris

5个赞,共90个帖子。

组: User

Some odd behavior here. When the "=" evaluation is removed the Assign() function breaks:

Assign odd behaviour.png
Assign odd behaviour.sm (3.14 KiB)已下载 1333 次。

Any thoughts?

I'm hoping to be able to assign multiple variables from a matrix like this:
Assign For Loop.png
Assign For Loop Broken.sm (5.11 KiB)已下载 1292 次。
#7 已发布: 2023/1/4 21:47:22
churichuro

churichuro

29个赞,共79个帖子。

组: User

a small workaround, could be to place the for inside a line command and return a false token value, it is not very clean but it works as far as I can see.



I think the assign command is not evaluated immediately, but has a delayed evaluation, which somehow only takes place after using the "=" symbol.
1位用户喜欢此帖子
Mark R Harris 2023/1/4 22:04:00
#8 已发布: 2023/1/5 11:30:01
overlord

overlord

600个赞,共1,381个帖子。

组: Moderator

Wrote

You can also use the Assign() function of the Maxima Plugin (this should work even without Maxima installed).


Assign() is a useful function and it doesn't need Maxima as you have indicated.
I don't (can't) use Maxima but I need Assign() sometimes.
And its codes have zero relation with Maxima functions.

This is why I suggested sometime ago that it could have relocated in another collective plugin.
CustomFunctions plugin is a good candidate for this purpose.
But I am not persistence, it is what it is.
Author of these plugins choose it this way.

Regards
1位用户喜欢此帖子
Mark R Harris 2023/1/5 18:24:00
#9 已发布: 2023/1/5 16:57:04
Martin Kraska

Martin Kraska

1,362个赞,共2,276个帖子。

组: Moderator

Wrote

Some odd behavior here. When the "=" evaluation is removed the Assign() function breaks:

Assign odd behaviour.png
Assign odd behaviour.sm (3.14 KiB)已下载 1333 次。

Any thoughts?

I'm hoping to be able to assign multiple variables from a matrix like this:
Assign For Loop.png
Assign For Loop Broken.sm (5.11 KiB)已下载 1292 次。



Two hints:

- The Assign function needs to be executed in order to do it's work, either by assigning the result to some dummy variable or by requesting display of the result.
- You don't need a loop, Assign() can handle vector arguments

Blatt10.png
Blatt10.sm (5.31 KiB)已下载 1377 次。
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
1位用户喜欢此帖子
Mark R Harris 2023/1/5 18:24:00
#10 已发布: 2023/1/5 17:22:41
Martin Kraska

Martin Kraska

1,362个赞,共2,276个帖子。

组: Moderator

Wrote

Wrote

You can also use the Assign() function of the Maxima Plugin (this should work even without Maxima installed).


Assign() is a useful function and it doesn't need Maxima as you have indicated.
I don't (can't) use Maxima but I need Assign() sometimes.
And its codes have zero relation with Maxima functions.

This is why I suggested sometime ago that it could have relocated in another collective plugin.
CustomFunctions plugin is a good candidate for this purpose.
But I am not persistence, it is what it is.
Author of these plugins choose it this way.

Regards



In general I don't care where Assign() is defined. It is in the Maxima plugin, because I needed a neat way to make use of results from Maxima functions like algebraic or ode solvers.

Yet I don't think that it would be a good idea to remove functions from plugins, because this would break the dependency management of existing sheets.

I don't know what happens if the same function is defined in multiple plugins. Would SMath crash? If not, which definition is used if both plugins are installed? One would see this in the dynamic help, but how to control?

BTW, I think that some day I'll revisit the Maxima plugin and if I get some help with a linux development tool chain and work flow I could perhaps make the plugin work also under linux. But that would require at least two months of full time work without distractions, because I would need to learn C# anew from scratch.

If someone is a master in C# I am happy to assist in refactoring and bug fixing of the plugin by providing the specifications and unit tests.

I'd be more comfortable with python or javascript but to my knowledge these aren't options for making plugins.
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
1位用户喜欢此帖子
Mark R Harris 2023/1/5 18:25:00
#11 已发布: 2023/1/6 02:15:05
Alvaro

Alvaro

1,139个赞,共1,805个帖子。

组: User

Hi. This could be another option.

Clipboard01.png

MyAssign 2.sm (10.52 KiB)已下载 1353 次。

Best regards.
Alvaro.
7位用户喜欢此帖子
⚜ Kenny Lemens, P.E. ᵂᴵ 2023/2/27 12:19:00, Вячеслав Мезенцев 2023/1/6 07:07:00, NDTM Amarasekera 2023/1/6 12:57:00, sergio 2023/1/6 14:23:00, churichuro 2023/1/6 16:19:00, bdrunagle 2023/1/6 16:21:00, Mark R Harris 2023/1/6 16:41:00
#12 已发布: 2023/1/6 16:25:18
churichuro

churichuro

29个赞,共79个帖子。

组: User

@Razonar, as usual with you, you give imaginative and useful solutions, it's great when people share their knowledge and help others, and with such a high technical level. thanks and congratulations.

I have a folder on my computer exclusively for the spreadsheets you share.
2位用户喜欢此帖子
Mark R Harris 2023/1/6 17:15:00, Alvaro 2023/1/6 23:10:00
#13 已发布: 2023/1/6 16:42:15
Arie

Arie

94个赞,共285个帖子。

组: User

In the event you may want to add descriptions to these definitions... a related thread:
https://en.smath.com/forum/yaf_postst23228_Assign-Description-to-Variable.aspx

It's a work around, but potentially useful.
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
3位用户喜欢此帖子
Alvaro 2023/1/6 23:10:00, sergio 2023/1/7 07:09:00, Mark R Harris 2023/1/6 16:50:00
#14 已发布: 2023/1/6 16:43:00
Mark R Harris

Mark R Harris

5个赞,共90个帖子。

组: User

Wrote

@Razonar, as usual with you, you give imaginative and useful solutions, it's great when people share their knowledge and help others, and with such a high technical level. thanks and congratulations.

I have a folder on my computer exclusively for the spreadsheets you share.



Yes indeed. Likewise. What churichuro said!
1位用户喜欢此帖子
Alvaro 2023/1/6 23:10:00
#15 已发布: 2023/1/6 23:11:34
Alvaro

Alvaro

1,139个赞,共1,805个帖子。

组: User

Thanks guys. I sincerely appreciate that.

Best regards.
Alvaro.
  • 有新帖
  • 无新帖