Quantcast
Channel: Active questions tagged string-manipulation - Mathematica Stack Exchange
Viewing all articles
Browse latest Browse all 186

How to convert the string "A^0" into the expression Superscript[A,0]?

$
0
0

I'm looking for a procedural way to define a symbol for a variable, based on a string. For instance, ToExpression["A^B"] gives us Power[A,B] (which, might be enough if we know that B will never get any value throughout the code).

However, as soon as we assign a number to B, we start getting troubles. For example, ToExpression["A^0"] evaluates to 1, ToExpression["A^(-1)"] evaluates to 1/A, and so on, but I would like to get Superscript[A,0] and Superscript[A,-1], and so on instead. How can I achieve that?


Viewing all articles
Browse latest Browse all 186

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>