Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Converting range variable into a vector, ultimatel...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-18-2010
01:29 AM

09-18-2010
01:29 AM

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".

Labels:

18 REPLIES 18

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-18-2010
03:39 AM

09-18-2010
03:39 AM

Re: Converting range variable into a vector, ultimately to find root

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-18-2010
04:59 AM

09-18-2010
04:59 AM

Re: Converting range variable into a vector, ultimately to find root

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-18-2010
05:17 AM

09-18-2010
05:17 AM

Re: Converting range variable into a vector, ultimately to find root

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.

Ashehad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-18-2010
05:23 AM

09-18-2010
05:23 AM

Re: Converting range variable into a vector, ultimately to find root

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.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.

Ashehad

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

How are the values for "f" found?

Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-18-2010
06:40 AM

09-18-2010
06:40 AM

Re: Converting range variable into a vector, ultimately to find root

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-18-2010
07:17 AM

09-18-2010
07:17 AM

Re: Converting range variable into a vector, ultimately to find root

Ashehad Ali wrote:

Its seems you're going round the houses to get your answer.

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

Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-20-2010
08:31 AM

09-20-2010
08:31 AM

Re: Converting range variable into a vector, ultimately to find root

Ashehad Ali wrote:

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-20-2010
07:09 AM

09-20-2010
07:09 AM

Re: Converting range variable into a vector, ultimately to find root

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.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.

Ashehad

Simple:

g[i := f(i)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-19-2010
09:16 AM

09-19-2010
09:16 AM

Re: Converting range variable into a vector, ultimately to find root

Have you deleted your other thread ?

Possibly answered [generally] here:

http://communities.ptc.com/message/152316#152316

jmG

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-19-2010
12:30 PM

09-19-2010
12:30 PM

Re: Converting range variable into a vector, ultimately to find root

jean Giraud wrote:

Have you deleted your other thread ?

Possibly answered [generally] here:

http://communities.ptc.com/message/152316#152316

jmG

Jean,

That link doesn't seem to be working.

The link to the other thread is below.

http://communities.ptc.com/thread/32637

Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-20-2010
01:14 AM

09-20-2010
01:14 AM

Re: Converting range variable into a vector, ultimately to find root

MIke Armstrong wrote:

jean Giraud wrote:

Have you deleted your other thread ?

Possibly answered [generally] here:

http://communities.ptc.com/message/152316#152316

jmG

Jean,

That link doesn't seem to be working.

The link to the other thread is below.

http://communities.ptc.com/thread/32637

Mike

Yes, broken link was reported many times.

Not acknowledged is not correct, simply !

Jean

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-20-2010
02:00 AM

09-20-2010
02:00 AM

Re: Converting range variable into a vector, ultimately to find root

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,

Ashehad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-20-2010
08:21 AM

09-20-2010
08:21 AM

Re: Converting range variable into a vector, ultimately to find root

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-20-2010
09:25 AM

09-20-2010
09:25 AM

Re: Converting range variable into a vector, ultimately to find root

Use spline interpolation rather than fitting a function to the data.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-21-2010
03:09 AM

09-21-2010
03:09 AM

Re: Converting range variable into a vector, ultimately to find root

Thanks Richard.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-20-2010
08:25 PM

09-20-2010
08:25 PM

Re: Converting range variable into a vector, ultimately to find root

"g" looks exponential,but not of the traditional forms.

jmG

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-21-2010
03:11 AM

09-21-2010
03:11 AM

Re: Converting range variable into a vector, ultimately to find root

Jean,

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

Ashehad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

01-22-2021
04:15 PM

01-22-2021
04:15 PM

Re: Converting range variable into a vector, ultimately to find root

Hello AshehadAl,

Please see the uploaded jpeg graphic.