cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Convert function name to string?

StuartBruff
Peridot

Convert function name to string?

Noticing in Prime Express that evaluating a function name yields a string, ... 

 

2020 04 04 A.jpg

I was wondering if anybody knows of a way to save that string to a variable?

 

 

(This is something that I asked for since about Mathcad 11 - it would have been quite handy to have when, say, evaluating a list of functions or identifying a function that's stored as an array element)

Tags (2)
4 REPLIES 4

Re: Convert function name to string?

The obvious doesn't work:

LucMeekes_0-1586108645653.png

Unfortunately the variable 'a' is NOT a string, as shown by:

LucMeekes_1-1586108691948.png

(Complains that "This value must be a string")

Instead, a is now (also) the sine function:

LucMeekes_2-1586108827549.png

Note: This works the same way in Mathcad 11:

LucMeekes_4-1586109123948.png

Success!
Luc

Re: Convert function name to string?

Thanks, Luc.

 

I already tried your suggestion, even though I knew it wouldn't work (otherwise assigning functions to names wouldn't!!), but I was wondering if there was some operation that would do the job, eg, something along the lines of converting a range variable into a vector, ...

 

2020 04 06 A.png

Re: Convert function name to string?

You might be able to do it in a program

       name <--sin

  return name

 

Constrained to Express, I can only speculate. . .

Re: Convert function name to string?

Hi Fred,

 

I hope it doesn't work! I frequently use(d) that particular form to generate and return constructed functions.

 

For example,

 

powgen(n) := f(x)<-n^x
p10 := powgen(10)
p10(3) = 1000

 

I've even used it within a program to iterate through a vector of functions to, say, compare their relative performance.

 

What we could possibly do with is a general purpose, Str(x), that converts its argument into a string regardless of of the argument's type. I wrote a version of Str that 'stringified' not just numbers, but also arrays as I had a need to exchange the data with another application, and also to be able to manipulate the data in its string form.

 

Unfortunately, I couldn't find a way to get Mathcad to return a string from a function.

 

Although having said that, I vaguely recall having found a way of doing it in M15 by playing with the xml. I might try finding my old M15 licence details ...

 

Stuart

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."