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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

## Converting range variable into a vector, ultimately to find root  1-Newbie

## Converting range variable into a vector, ultimately to find root

Hi All,

Is there an easier way to convert a range variable into a vector? That is, suppose we have a list of data (perhaps huge) in a single table over a range. Infact, this range variable is the output of a part of programming in mathcad. How to convert this in to a vector? Once I can convert this into a vector, then I can easily locate roots using curve "fitting".

18 REPLIES 18  16-Pearl

If you have a range variable, say i:=0:10, you can create the vector x with values 0 to 10 simply by x[i:=i (where the '[' symbol provides a subscript in Mathcad - it's a pity the text formatting in these posts doesn't allow subscripts given the frequency with which they're used in Mathcad).

Alan  5-Regular Member
(To:AlanStevens)
 Alan Stevens wrote:it's a pity the text formatting in these posts doesn't allow subscripts given the frequency with which they're used in Mathcad).Alan

Alan,

Just one of many problems with the website. It surely isn't hard to implement subscript/superscript formatting options.

Image attached.

Mike  1-Newbie
(To:MikeArmstrong)

Suppose the range variable is as follows:

For i:=1...4, we have f(i):= 0.001, 0.0019,0.0025, 0.0031

I would like to convert these four values of f(i) into a single vector, say "g". Note that I don't want to copy each value and type it over and over.  5-Regular Member
 Ashehad Ali wrote:Suppose the range variable is as follows:For i:=1...4, we have f(i):= 0.001, 0.0019,0.0025, 0.0031I would like to convert these four values of f(i) into a single vector, say "g". Note that I don't want to copy each value and type it over and over.Ashehad

Why can't you simply create a vector of the required values?

How are the values for "f" found?

Mike  1-Newbie
(To:MikeArmstrong)

I've managed to work out. I don't know what was the error though. Writing f subscript i and equating it to f(i). Then computing f gives me the vectorised form, so simple. It didn't use to give me before, however.  5-Regular Member
 Ashehad Ali wrote:I've managed to work out. I don't know what was the error though. Writing f subscript i and equating it to f(i). Then computing f gives me the vectorised form, so simple. It didn't use to give me before, however.

You could post a worksheet so other collabs will offer a different approach.

Mike  5-Regular Member
 Ashehad Ali wrote:I've managed to work out. I don't know what was the error though. Writing f subscript i and equating it to f(i). Then computing f gives me the vectorised form, so simple. It didn't use to give me before, however.

You shouldn't, in general, re-use the function name (f) as the new vector's name(also f). It is much better to use a different name for the results vector, so that after you have created the vector you can still use the function (by its name). It is easy to start getting lots of 'error messages' when mathcad (or is that you;-) is getting confused as to which version of 'f' it is using.

Because mathcad is a functional style language, you can pass not only strings, scalars, vectors and matrices to functions, but you can also pass functions by name into functions. This can be amazingly powerful, but does leave one open to forgetting that you can't have the same name for more than one thing at a time.

If you do wish to re-use names, then look up the "MathStyles", which are 8 differentiating tags for names, and can have differentiating formattiong to go with them. Unfortunately they lack good shortcuts so are rarely used.

Philip  1-Newbie
 Ashehad Ali wrote:Suppose the range variable is as follows:For i:=1...4, we have f(i):= 0.001, 0.0019,0.0025, 0.0031I would like to convert these four values of f(i) into a single vector, say "g". Note that I don't want to copy each value and type it over and over.Ashehad

Simple:

g[i := f(i)  1-Newbie

jmG  5-Regular Member
(To:jeanGiraud)

Jean,

That link doesn't seem to be working.

Mike  1-Newbie
(To:MikeArmstrong)

Yes, broken link was reported many times.

Not acknowledged is not correct, simply !

Jean  1-Newbie
(To:jeanGiraud)

Here's the file which I have been working with that kind of stimulated the discussion of this subject. The data in the table F corresponds to functions f and g, which are outcomes of a part of a programming. f and g behave as "log" and "exponents", respectively. See the graph. I'm not confident with the root which I've got. I think it's the curves that I fitted are incorrect. Could someone improve the root by using alternative fitting perhaps? Just noting that the vectors v1 and v2 are parameters for the guess estimates of log and exponentials.

Cheers,  16-Pearl

Plot the fits and the points together on the same graph. By eye they look reasonable in the region where they cross (i.e. near the root). However, you haven't specified the accuracy you want, so it's difficult to say if the result is good enough.

Alan  19-Tanzanite

Use spline interpolation rather than fitting a function to the data.  1-Newbie
(To:RichardJ)

Thanks Richard.  1-Newbie

"g" looks exponential,but not of the traditional forms. jmG  1-Newbie
(To:jeanGiraud)

Jean,

You are certainly right. I didn't know if there was any other alternative to fitting as suggested by Richard.   