Skip to main content
5-Regular Member
Aug 6, 2026 7:45 PM UTC
Question

Expansion formula for cos(n*x) yields unexpected results

The following Mathcad code attempts to use a formula from Wikipedia to expand cos(n*z), but appears to get the wrong result. Comments?

 

Mathcad code implementing expansion formula

 

14 replies

24-Ruby IV
Aug 7, 2026 3:45 PM UTC

It's better to attach your file in the archive here.

Translate
5-Regular Member
Aug 7, 2026 4:09 PM UTC

Great! I looked for somewhere to upload my file, but couldn’t find it. How do I do it?

Translate
DJNewman
19-Tanzanite
Aug 7, 2026 4:20 PM UTC
PTC Community reply workflow

 

Translate
PTC Marketer for Creo and Mathcad. I run their YouTube channels, some Creo campaigns, and all Mathcad campaigns and communications.
5-Regular Member
Aug 7, 2026 4:37 PM UTC

Image file of embedded picture in the original post

Translate
23-Emerald V
Aug 7, 2026 8:29 PM UTC

That is still a picture. 

Better is to upload the prime worksheet file ( .xmcd).

But you will have to .zip it first and upload that .zip file.

Also you should indicate which version of Prime you are using.

 

Success!

Luc

Translate
Werner_E
25-Diamond I
Aug 7, 2026 8:42 PM UTC

I can’t test it in Prime as I have no access to a full version of Prime, but I agree that Prime’s result of the symbolic evaluation which you highlighted in yellow is wrong. It should be cos(2z), equivalent to 2 cos²(z)-1 as you wrote.

You may consider contacting official PTC support and report this bug in the symbolic engine.

 

BTW, interestingly its even worse in legacy Mathcad 15 (with muPad as its symbolic engine):

The error messages displayed are confusing and I can't make sense of them.

 

My first guess was that it may have to do with a faulty implementation of the ‘combin’ function, but this seems not to be the case:

 

Nonetheless MC15’s symbolics returns wrong results. Calculation of the following two expressions should be the same as “i” only has the value 0. Nonetheless only hard coding the zero as limit of the second sum gives the correct result.

Mathcad 15 is not supported anymore and so bugs in this legacy version will not be fixed. But since Prime is based on Mathcad, it's possible that a bug from the older version was carried over to Prime.

 

I attach the file in MC11 format so maybe ​@LucMeekes  would like to give it a try with his Mathcad 11 (which uses Maple for symbolic evaluations).

 

Translate
23-Emerald V
Aug 8, 2026 9:20 PM UTC

Each version has its peculiarities. Mathcad 11 gives:
 

It's not wrong, but unfortunately the maple symbolics don't understand the combin function.

But when defined:
 

Success!
Luc

Translate
Werner_E
25-Diamond I
Aug 8, 2026 10:41 PM UTC

No big surprise that Maple in MC11 performs way better than later versions.

Here is the MC15 result when redefining the ‘combin’ function - the results are OK, the usage of DOM_SET a bit strange

 

​@AD_2895922 

Which result do you get in Prime when you redefine the “combin” function (either using factorials or the Gamma function)?

Translate
5-Regular Member
Aug 8, 2026 3:12 PM UTC

So, here’s the zip file.

Translate
19-Tanzanite
Aug 9, 2026 8:44 AM UTC

Here’s what I get in Prime 12:

 

Translate
Werner_E
25-Diamond I
Aug 9, 2026 9:18 AM UTC

So the bug is already fixed in Prime 12.

Would the usage of a modifier like ‘simplify’ or ‘expand’ avoid the second symbolic evaluation of the two sums?

Translate