Skip to main content
5-Regular Member
August 6, 2026
Question

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

  • August 6, 2026
  • 14 replies
  • 202 views

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
August 7, 2026

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

5-Regular Member
August 7, 2026

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

DJNewman
19-Tanzanite
August 7, 2026
PTC Community reply workflow

 

PTC Marketer for Creo and Mathcad. I run their YouTube channels, some Creo campaigns, and all Mathcad campaigns and communications.
5-Regular Member
August 7, 2026

Image file of embedded picture in the original post

23-Emerald IV
August 7, 2026

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

Werner_E
25-Diamond I
August 7, 2026

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

 

23-Emerald IV
August 8, 2026

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

Werner_E
25-Diamond I
August 8, 2026

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)?

5-Regular Member
August 8, 2026

So, here’s the zip file.

19-Tanzanite
August 9, 2026

Here’s what I get in Prime 12:

 

Werner_E
25-Diamond I
August 9, 2026

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?