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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

illegal context when range is multiplied

ptc-6714823
1-Visitor

illegal context when range is multiplied

Hi,

Hope you guys can help.

I can print out the range multiplied by some value:

RTn9M.png

Why can't I store the resulting range in the variable?

18 REPLIES 18

Add tu as a subscript to tv by typing tv[tu.

Clipboard01.bmp

Werner_E
25-Diamond I
(To:ptc-6714823)

greg re wrote:

Hi,

Hope you guys can help.

I can print out the range multiplied by some value:

Why can't I store the resulting range in the variable?

Because a range is an implicit loop, not an a array of values. Use a vector instead of a range.

Further to Werners suggestion, see below.

Clipboard01.bmp

I have used an undocumented feature to turn tu from a range to a vector by in-line evaluation.

Mike,

What version of Mathcad is that? My 15 M030 won't do that.

Fred Kohlhepp wrote:

Mike,

What version of Mathcad is that? My 15 M030 won't do that.

This undocumented feature exists since inline evaluation was intruduced.

I am using the same version as yours and it works OK, although I get different display of the inline eval than Mike:

1.png

Dang!!

Learn something every day! Neat!

Fred Kohlhepp wrote:

Dang!!

Learn something every day! Neat!

And it's a Friday

This feature is useful when the range is small and can be evaluated.

Werner Exinger wrote:

Fred Kohlhepp wrote:

Mike,

What version of Mathcad is that? My 15 M030 won't do that.

This undocumented feature exists since inline evaluation was intruduced.

I am using the same version as yours and it works OK, although I get different display of the inline eval than Mike:

1.png

I think it has something to do with the display option settings.

Double left click, look under display options tab. I have the 'matrix display style' set to Matrix. I believe yours will be set as Automatic?

Clipboard01.bmp

Mike Armstrong wrote:

Werner Exinger wrote:

Fred Kohlhepp wrote:

Mike,

What version of Mathcad is that? My 15 M030 won't do that.

This undocumented feature exists since inline evaluation was intruduced.

I am using the same version as yours and it works OK, although I get different display of the inline eval than Mike:

I think it has something to do with the display option settings.

Yes is has. The way the result is displayed depends on the global display settings (which are "automatic" as you correctly guessed) and cannot be changed for that region alone. Thats one of a few mysteries of the inline eval.

Fred Kohlhepp wrote:

Mike,

What version of Mathcad is that? My 15 M030 won't do that.

I am using M030 Fred.

Thanks for your answers, guys.

I am using subsript feature suggested by Mike Armstrong, but it still does not work:

math.PNG

LiL is still one thing that keeps formula from being computed.

Please upload the worksheet again.

math.PNG

Not a picture ,the worksheet. You can do this by clicking 'use advanced editor'.

a few comments:

1. the range K is specified so that it returns a 1 element range K = 0.1 (is this what you meant?)
If you only use start & end on the range , I think, mathcad assumes a step size of 1

2.either add the iL range to the Qe variable or remove it from the L .

Mathcad can do either.

Capture.PNG

3.when you ask mathcad to multiply two variables dependant on the same range variable , it can assume that the result should be vectorised ( the same calculation repeated for each step of the range variable.

if, as here you have 2 independant range variables mathcad cannot decide what you want and reports an error.

If it should give a 2 D matrix as the result , then you will need to write this explicitly.

If you want each step to calculate , incrementing the value of , both iL and K, then K needs to be created with an equation based on iL.

Mathcad cannot combine ranges of different lengths

Andy

Thanks for the tip.

Have a look in the attached worksheet. There is a user defined function called vec which accepts ranges, range variables and converts them into a vector. Use this instead of using ranges.

Remember you may have to explicitly vectorize using this method.

Sorry am too busy to work through it at the moment.

Werner_E
25-Diamond I
(To:ptc-6714823)

greg re wrote:

Thanks for the tip.

You are replying to your own post, so its not clear what tip you mean.

Why are you still using a lot of ranges when is was already said a couple of times here that you should use vectors?

You are defining some ranges in a way which shows that it seems to be not clear to you what a range is and how range definitions work.

1) K:=0.1 .. 0.15 what do you think that this definition is creating? It will create just a range with a single value.

2) G1:=50 .. 10^(-1) Again, what did you expect to get? You again do not specify a step width by providing the second value, so you get a range from 50 to 1 with step 1.

What do you expect to get when you calculate G? This expression is (mongst others) dependent on 2 variables L and K, which you defined as ranges. What do you expect that G would look like? If you excpect a 2D table you would have to explicitely create it, as Andy already pointed out.

Keep in mind that a range is not a data structure consisting of a couple of values like a vector. You can look at a range as being an iterator, an implicit loop. So you should use ranges in three situations only:

- to index vectors and matrices

- in aprogramming conntext to define a loop

- as abscissa value in a 2D plot

For further information please read on here: http://communities.ptc.com/docs/DOC-6073

Announcements

Top Tags