Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

Working with complex numbers in C-Script block

+1 vote
72 views

Hi, 

I'm trying to make complex numbers operations in a C-Script in my model, but when i try to compile the next error is shown:

source:78:38: error: imaginary constants are an extension

I'm including the file "complex.h", and I defined the numbers as a + b * I for example. 

Have anyone worked with complex numbers and succesfully compiled the C-Script?

Best regards,

Sebastián Neira.

asked Jan 30 by sfneira (13 points)

1 Answer

+1 vote

Hi,

you can work around the extension error by defining your own imaginary constant:

const double complex i = csqrt(-1);

However, depending on your operating system you'll most likely see other errors later. In short, we do not support complex calculations in C-Scripts at this time, but we'll see whether this can be improved in a later release.

Kind regards,

Oliver Schwartz

answered Jan 30 by Oliver Schwartz (114 points)
edited Jan 30 by Oliver Schwartz
...