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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Iteration Sequence and difference in results Prime and MAthcad

albertschepers
5-Regular Member

Iteration Sequence and difference in results Prime and MAthcad

I am running the same function in Prime and Mathcad but get different results. See attached

 

 

7 REPLIES 7


@albertschepers wrote:

I am running the same function in Prime and Mathcad but get different results. See attached

 

 


No, you are not running any functions at all!

All I see is a misuse of ranges.

You may have noted that the results of your "calculations" is NOT a vector and that you can't assign it to a variable and use it for later calculations.

A range is sort of an implicit loop and the order those loops for i and j are executed obviously has changed in Prime. But the results are the same anyway, of course.

If you use those ranges in a correct way, you get the very same results in Prime and in real Mathcad:

B.png

albertschepers
5-Regular Member
(To:Werner_E)

Thank you for the prompt response. Also thank you for the reminder that these are called range variables. Attached is my final work sheet with the final formula creating a vector based on the two rang variables. Please note that the range variables are used correctly. Also the final formula has the same results in both Prime and Mathcad.

 

At issue is the intermediate results between Prime and Mathcad. You will notice the use of the range variables is complex to determine the desired final vector values and I would have assumed that Prime and Mathcad would determine the intermediate results, the derivation of formulas for the range variables, similarly. They don't. Prime's results are wrong, or at least not useful in developing the final formula.

 

Please note I attempted to attach a screen shot but it failed, the error message is there are two many characters. Perhaps there is another way of inserting a screenshot than clipping and pasting.

 

 

Can you explain what you determine to be 'intermediate results'

and why you think they are wrong (in Prime)?

 

Luc

 

You cannot copy & paste pictures in this forum. You have to save your screenshot (or other picture) in a file (.png gives the sharpest pictures) and insert them with the 'Photos' button just above the edit pad.

albertschepers
5-Regular Member
(To:LucMeekes)

if you look at the first posted files you will see a difference in the results for the range variable formulas I am working on.  I try these and build on them until I get the results I need.  Once complete I simplify the formulas to make them as elegant as possible.

 

What happens is Prime and Mathcad throw different results due to the order in which range variables are used or iterated on, see Werner's screen shot in his last post, it is very clear what is happening. My screen shot shows the final form as well as the intermediate. The subscript for the node vector has several terms in it each of which I tested before combining.  It is this testing of the intermediate terms that is done differently in Prime and Mathcad (see Werner's posted image).

 

range variable.png

What you call "testing" and "intermediate results" is simply wrong usage of ranges.

The "results" you get are useless for any calculations anyway and you should by all means avoid doing so.

Ranges should be used only in three situations:

1) Provide a range for plotting

2) in a for-loop inside a program

3) to index vectors and variables.

Ah, I guess I see what bothers you:

LM_20190220_Iterate.png

You CANNOT depend on the order of execution of simultaneously used range variables.

Since addition is commutative, Mathcad may choose to start evaluation of any expression from left to right, or from right to left or any other order. And you must not be surprised if it differs from (sub-)version to (sub-)version of Mathcad and/or Prime, even from equation to equation on the same sheet!

 

Success!

Luc

albertschepers
5-Regular Member
(To:LucMeekes)

You got it!

 

One more point of interest, once I have the correct formulation I use the symbolic solver to simplify the formula (I should have posted it before). When I do the formula is reduced to something that is quite elegant and works.

 

 

Now to see if I can prepare similar formulas for the coordinates of each node.

 

Thank you for your assistance.

 

 

Top Tags