String to Variable Name (str2var)

String to Variable Name (str2var) - Messaggi

#1 Pubblicato: 31/12/2022 02:33:45
Mark R Harris

Mark R Harris

5 apprezzamenti in 90 post.

Gruppo: 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 Pubblicato: 31/12/2022 04:28:45
Вячеслав Мезенцев

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

1.558 apprezzamenti in 1.868 post.

Gruppo: Moderator

File non trovato. File non trovato.

str2num_full.png
Russia ☭ forever, Viacheslav N. Mezentsev
4 utenti hanno apprezzato questo post
Mark R Harris 31/12/2022 06:43:00, NDTM Amarasekera 31/12/2022 10:10:00, overlord 01/01/2023 15:20:00, sergio 31/12/2022 08:09:00
#3 Pubblicato: 31/12/2022 06:43:07
Mark R Harris

Mark R Harris

5 apprezzamenti in 90 post.

Gruppo: User

Thank you so much uni!
#4 Pubblicato: 01/01/2023 12:51:50
Laurent Fournier

Laurent Fournier

9 apprezzamenti in 66 post.

Gruppo: User

WOW!!!
#5 Pubblicato: 02/01/2023 06:31:00
Martin Kraska

Martin Kraska

1.361 apprezzamenti in 2.275 post.

Gruppo: 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) scaricato 1340 volta(e).
assign.PNG
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
2 utenti hanno apprezzato questo post
sergio 02/01/2023 07:35:00, Mark R Harris 02/01/2023 17:02:00
#6 Pubblicato: 04/01/2023 20:02:47
Mark R Harris

Mark R Harris

5 apprezzamenti in 90 post.

Gruppo: 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) scaricato 1317 volta(e).

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) scaricato 1271 volta(e).
#7 Pubblicato: 04/01/2023 21:47:22
churichuro

churichuro

29 apprezzamenti in 79 post.

Gruppo: 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 utenti hanno apprezzato questo post
Mark R Harris 04/01/2023 22:04:00
#8 Pubblicato: 05/01/2023 11:30:01
overlord

overlord

600 apprezzamenti in 1.381 post.

Gruppo: 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 utenti hanno apprezzato questo post
Mark R Harris 05/01/2023 18:24:00
#9 Pubblicato: 05/01/2023 16:57:04
Martin Kraska

Martin Kraska

1.361 apprezzamenti in 2.275 post.

Gruppo: 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) scaricato 1317 volta(e).

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) scaricato 1271 volta(e).



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) scaricato 1350 volta(e).
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
1 utenti hanno apprezzato questo post
Mark R Harris 05/01/2023 18:24:00
#10 Pubblicato: 05/01/2023 17:22:41
Martin Kraska

Martin Kraska

1.361 apprezzamenti in 2.275 post.

Gruppo: 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 utenti hanno apprezzato questo post
Mark R Harris 05/01/2023 18:25:00
#11 Pubblicato: 06/01/2023 02:15:05
Alvaro

Alvaro

1.139 apprezzamenti in 1.805 post.

Gruppo: User

Hi. This could be another option.

Clipboard01.png

MyAssign 2.sm (10,52 KiB) scaricato 1338 volta(e).

Best regards.
Alvaro.
7 utenti hanno apprezzato questo post
⚜ Kenny Lemens, P.E. ᵂᴵ 27/02/2023 12:19:00, Вячеслав Мезенцев 06/01/2023 07:07:00, NDTM Amarasekera 06/01/2023 12:57:00, sergio 06/01/2023 14:23:00, churichuro 06/01/2023 16:19:00, bdrunagle 06/01/2023 16:21:00, Mark R Harris 06/01/2023 16:41:00
#12 Pubblicato: 06/01/2023 16:25:18
churichuro

churichuro

29 apprezzamenti in 79 post.

Gruppo: 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 utenti hanno apprezzato questo post
Mark R Harris 06/01/2023 17:15:00, Alvaro 06/01/2023 23:10:00
#13 Pubblicato: 06/01/2023 16:42:15
Arie

Arie

94 apprezzamenti in 285 post.

Gruppo: 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 utenti hanno apprezzato questo post
Alvaro 06/01/2023 23:10:00, sergio 07/01/2023 07:09:00, Mark R Harris 06/01/2023 16:50:00
#14 Pubblicato: 06/01/2023 16:43:00
Mark R Harris

Mark R Harris

5 apprezzamenti in 90 post.

Gruppo: 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 utenti hanno apprezzato questo post
Alvaro 06/01/2023 23:10:00
#15 Pubblicato: 06/01/2023 23:11:34
Alvaro

Alvaro

1.139 apprezzamenti in 1.805 post.

Gruppo: User

Thanks guys. I sincerely appreciate that.

Best regards.
Alvaro.
  • Nuovi post
  • Nessun nuovo post