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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Bug in Symbolics or ignorance on my part?

rag
1-Newbie
1-Newbie

Bug in Symbolics or ignorance on my part?

Can anybody explain, why the variable x is not known by the symbolics machine? Is this a bug or am I doing something wrong?

In my original file x would be a much larger list of more or less arbitrary numbers which can not be derived by a function. I mention this, because defining x.i:=3*i would not produce that error.

Regards

WR

Symb_Err.png

29 REPLIES 29
ValeryOchkov
24-Ruby IV
(To:rag)

An other variant:

SymSum.png

ValeryOchkov
24-Ruby IV
(To:rag)

I think we cannot use this operator in symbolic calculation:

SunProdSym.png

RichardJ
19-Tanzanite
(To:rag)

It doesn't like the way you have defined the vector "a". I'm not sure if the way you are doing that is officially supported or not (I have seen it before, but I can't find it anywhere in the documentation). If it is, then it's a bug. If not, then arguably it isn't. If you define your vector using insert matrix or insert data table, it works.

The construct is a comma-separated vector.

Mona

RichardJ
19-Tanzanite
(To:mzeftel)

OK, it is documented

So the fact that the symbolics will not recognize it is a bug.

RichardJ
19-Tanzanite
(To:RichardJ)

It looks like the way both the numeric and symbolic processors handle this construct could do with a little work

comma separated vector.png

rag
1-Newbie
1-Newbie
(To:RichardJ)

Thats funny. I wonder what Mathcad thinks that v is in your first definition. At least you cannot access the individual components of that "vector".

As for the initial questions it seems to me now that it is really a bug with the integration of the symbolic processor in Mathcad. Comma-separetd vectors are not recognized as such by the symbolics. It takes a redefinition combined with using the numeric processors "=" to make it work.

Symb_Err2.png

I had chosen to use the comma-separted vector because it seemed the most easy way to type in a 26 row vector (representing the occurences of the letters of the alphabet in a given Text). By the way - is it possible in Mathcad to read in a textfile in ASCII or even ANSI format and do some statistical analysis (e.g. like counting the frequency of the lettters)?

Regards WR

wayne
3-Visitor
(To:rag)

tmp.gif

RichardJ
19-Tanzanite
(To:rag)

Thats funny. I wonder what Mathcad thinks that v is in your first definition.

I have no idea. I was surprised I didn't get a syntax error. I tried it because, logically (to me), it should work, and yield a vector with the elements 2,3,4,5,6,7. I also find it illogical that I can assign a list of 6 elements to v[j when j only takes on 2 values!

By the way - is it possible in Mathcad to read in a textfile in ASCII

Sure. READPRN won't do what you need?

or even ANSI format

Mathcad strings handle ANSI codes. Have to tried reading an ANSI file into Mathcad?

do some statistical analysis (e.g. like counting the frequency of the lettters)?

Sure. Just convert the string to a vector using str2vec, and then analyze the vector using the hist or histogram functions.

wayne
3-Visitor
(To:RichardJ)

I have no idea. I was surprised I didn't get a syntax error. I tried it because, logically (to me), it should work, and yield a vector with the elements 2,3,4,5,6,7. I also find it illogical that I can assign a list of 6 elements to v[j when j only takes on 2 values!

You don't need to define j first, I think the scope of the index is within the definition of the comma separated vector value only (i.e. not the same j), just like for the table.

RichardJ
19-Tanzanite
(To:wayne)

You don't need to define j first

But you do. If you don't define j then you get what I showed at the top of the image I posted.

wayne
3-Visitor
(To:RichardJ)

OOPS,
you are right, I should be more careful. I was also wrong, you can do math in the cell.

The data table does not required j, but you can't do math.

rag
1-Newbie
1-Newbie
(To:RichardJ)

By the way - is it possible in Mathcad to read in a textfile in ASCII

Sure. READPRN won't do what you need?

I have tried it, but got an "Encountered a file I/O error". Think that command is meant for input of numerical space delimeted data and not for arbitrary text. On the one side the help states "READPRN("file") Returns an array containing the contents of the ASCII file." which sounds good for my purpose, but later ist states "Files should be ASCII text only, with data arranged in rows and columns separated by spaces or tabs. A text header is allowed; however, once READPRN encounters a number, it assumes data has begun, so headers should contain no numbers." On my tries, READPRN only returned the numbers in the text, not the letters.

I have tried data components, too, but with no avail. I got part of the lines of text in the array, but usually for unknown reason the first few letters of every line are missing.

Using READFILE with type "fixed" I would have to specify a vector consisting of the lenght of every single line in the file - not suitable for "unknown" textfiles.

I have not worked in it, but maybe its possible to play around with READBIN to get it to work, but not that easy, I suspect.

WR

RichardJ
19-Tanzanite
(To:rag)

Can you post the file here?

rag
1-Newbie
1-Newbie
(To:RichardJ)

Richard Jackson schrieb:

Can you post the file here?

Sure. In the meantime i played around a little bit with READPRN and READFILE. READPRN can't do the job because it expects numbers in ANSI format arranged in columns. But concerning READFILE I misunderstood the meaning of the third vector-parameter. Using it correctly, it works now. See the attached file - maybe there are ideas of doing some things a better way.

Another question came up while working on the sheet: Is it not possible to use a range variable inside of a program? (See attached sheet for further deteails).

Regards

WR

wayne
3-Visitor
(To:rag)

A variable can have a numerical value and a symbolic value.

After assigning a numeric value, to use the symbolic value, you must do as you did, x:=x

Inside a program, you must constuct the loop as you did (I think it's better that way).

One test:

aa.png

I hope the operator clear in Mathcad Prime 2.0 will be more logic.

Valery Ochkov schrieb:

One test:

aa.png

The a --> a is logic enough for me

rag
1-Newbie
1-Newbie
(To:wayne)

A variable can have a numerical value and a symbolic value.

If a variable has a numerical value that value will be shown via symbolics as well, maybe a little bit more exact.

After assigning a numeric value, to use the symbolic value, you must do as you did, x:=x

No. a:=a is meant for another purpose. That way you can use the variable a in symbolic operations as if it would have no value, e.g. solve an equation for a or the like.

Im my case not the frequ:=frequ does the job but rather the numerical = by which it is followed. The assign operator assigns to the left hand side the expression which is farthest to the right. So the problem seems to be, that the definition of freq by that little program is internally not stored as the solution vector but as a program. And it seems that the symbol processor can not operate on that. By explicitly numerically evaluating the program for freq and assigning that to freq again assigns a regular vector which the symbolics are happy with. Would call it a bad integration of the symbolic processor into the number cruncher.

Inside a program, you must constuct the loop as you did (I think it's better that way).

Yes, looks like thats true. But why are range variables bad in programs and is that documented somewhere?

WR

wayne
3-Visitor
(To:rag)

Perhaps your specific problem is more complicated, but typing a:=a in the following tells the symbolic processor to use the symbolic value of a, otherwise the numeric value will be used (in the symbolic processor)

tmp.gif

Yes, looks like thats true. But why are range variables bad in programs and is that documented somewhere?

For the range variable in a program, where's the end of the loop? What if you had 2 range variables, how would the program proceed? Just thinking that it would be problematic.

rag
1-Newbie
1-Newbie
(To:wayne)

Perhaps your specific problem is more complicated, but typing a:=a in the following tells the symbolic processor to use the symbolic value of a, otherwise the numeric value will be used (in the symbolic processor)

Thinks its a little bit different. A variable has a numeric and a symbolic value. If a numeric value is assigned to a variable, this value ist stored as numeric AND as symbolic value. If a symbolic expression which cannot be evaluated at the time of assignment is assigned, the numeric value is "undefined" and the symbolic value is that symbolic expression. It is not possible for a variable to have a valid numeric value AND a symbolic value which is a different symbolic expression - but ther is one exception. A very special is the self redefinition var:=var. Its kind of a clearing action for the symbolic part of the variable but leaves intact the numeric part. So a variable can have a numeric value while the symbolic value is the variable itself.

So var:=var does not activate in some way the symbolic part of the variable, but rather clears that part. Its a long standing and heaviliy discussed wish in the collab to have a possibility to clear the numeric part, too.

Seeing it that way i find it logic in Valerys example, that after a:=a he gets a->a and not a->b.

As it is implemented there is no way that a variable can have a valid numeric value and an expression other that itself as a numeric value.

In my initial question it seems that i managed to construct a situation, where the numerical part of the variable is a number and the symbolical is undefined - possibly because of a bug in the integration of range variables in the symbolics machine. So it looks to me, that at the time of an assignment the right hand side is evaluated two times (numerically and symbolically) and if there is a valid numeric representation, most of the time both processors come to the same result, but there are expressions that the numeric and there even are expression that the symbolics cannot evaluate.

var_numsym1.png

For the range variable in a program, where's the end of the loop? What if you had 2 range variables, how would the program proceed? Just thinking that it would be problematic.

A range variable has distinct beginning and end, so no problem with the loop ending. Maybe it would be possible to construct some pathologic examples, but then they possible would not work outside a program, too. I simply wonder why range variables don't behave the same way in a program than in a standalone expression.

BTW - anybody having better ideas for the character counting in my previously posted worksheet? (http://communities.ptc.com/message/175537#175537)

wayne
3-Visitor
(To:rag)

Thanks Winfrod

I think Valery would like the symbolic's to go further, so that he could get a->b, however since a and b are equivalent, it's not wrong to say a->a.

Based on my limited understanding, I would expect the results in both Valary's and your example, with the exception that I never tried with a sum as in your last example. I don't know how to define a vector symbolically in Mathcad, so can't expect a symbolic result, but I agree that you should expect to get a numerical result from the Symbolic processor.

For a range variable; the range variable is active until you redefine the variable, so if in a program it would be active until you redefine or end. I understand that you could use it, but the order of calculations, especially in sub loops, boolean expressions and using with multiple range variables I think can be problematic; and including it does not really add anything significant.

RichardJ
19-Tanzanite
(To:rag)

Another question came up while working on the sheet: Is it not possible to use a range variable inside of a program? (See attached sheet for further deteails).

It is possible to use a range variable in a program, although not in the way you are using it. It's pointless though. A for loop requires the same number of lines to fill the vector, so why use a range variable?

Pointless_range.png

PhilipOakley
5-Regular Member
(To:rag)

winfrod rager wrote:

I had chosen to use the comma-separted vector because it seemed the most easy way to type in a 26 row vector (representing the occurences of the letters of the alphabet in a given Text).

Regards WR

I use v:=stack(1,2,3,4,5,6,7... ) if I want a compact one liner.

Its quicker to type than inserting a row matrix and applying a transpose(ctrl+!)

Philip

I use v:=stack(1,2,3,4,5,6,7... ) if I want a compact one liner.

Its quicker to type than inserting a row matrix and applying a transpose(ctrl+!)

Thanks for this - I like that method!

WR

wayne
3-Visitor
(To:rag)

I agree, I would have thought that stack (and augment) would have required matrices. You can also do math.

Thanks, Philip

I think it is a bug. Frequently I get that message (Undefined variable) and I solve the problem only by deleting the variable and typing it again in the affected equation.

I think it is a bug. Frequently I get that message (Undefined variable) and I solve the problem only by deleting the variable and typing it again in the affected equation.

I tihnk that is something different. Next time it happens please post the worksheet here.

I don't think the symbolic algorithm should be able to do a summation on a range variable. Range variables are for indexes. Valery has shown how everything works if you create a real vector. The "comma separated vector" appears to be still a range variable, not a vector. I wouldn't regard this as a bug.

Top Tags