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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Bode Plot - NaN/Complex values Error and Plot Grid Does Not Exist in Mathcad Prime 7

Cornel
19-Tanzanite

Bode Plot - NaN/Complex values Error and Plot Grid Does Not Exist in Mathcad Prime 7

Hello,

How can I get rid of that error in red below? I want to plot the Bode graphs of amplitude-frequency and phase-frequency in Mathcad Prime 7.

Also, I want to have grid on in these graphs. How can I do that in Mathcad Prime 7?

 

CornelBejan_0-1665740134495.png

CornelBejan_10-1665741063475.png

 

CornelBejan_11-1665741075203.png

 

Mathcad Prime 7 file is attached.
Thank you.

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:Cornel)

You left freq undefined, so Prime will try to range freq from -10 to 10. Of course that doesn't work on a logarithmic scale. In addition freq needs a unit (Hz or so).

You can solve this problem simply by defining freq as:

LucMeekes_3-1665742849598.png

But this creates a lot of superfluous points for a log scale. And when you want to go over 6 decades it's not going to work.

 

You can use logpts() or logspace() to generate a vector of logarithmically spaced points for freq:

LucMeekes_0-1665742233144.png

To get 10 points per decade from 10^0(=1) to 10^3(=1000) Hz.

Now you need to vectorise the plot expressions.

You can use the unit deg instead of multiplying the argument with 180/pi, and i is a predefined constant, you don't need to define j.

This gets:

LucMeekes_1-1665742399789.png

and

LucMeekes_2-1665742420719.png

Success!
Luc

View solution in original post

26 REPLIES 26
LucMeekes
23-Emerald III
(To:Cornel)

You left freq undefined, so Prime will try to range freq from -10 to 10. Of course that doesn't work on a logarithmic scale. In addition freq needs a unit (Hz or so).

You can solve this problem simply by defining freq as:

LucMeekes_3-1665742849598.png

But this creates a lot of superfluous points for a log scale. And when you want to go over 6 decades it's not going to work.

 

You can use logpts() or logspace() to generate a vector of logarithmically spaced points for freq:

LucMeekes_0-1665742233144.png

To get 10 points per decade from 10^0(=1) to 10^3(=1000) Hz.

Now you need to vectorise the plot expressions.

You can use the unit deg instead of multiplying the argument with 180/pi, and i is a predefined constant, you don't need to define j.

This gets:

LucMeekes_1-1665742399789.png

and

LucMeekes_2-1665742420719.png

Success!
Luc

Cornel
19-Tanzanite
(To:LucMeekes)

It is a little strange because if I do not put the units (meaning rad/s) for wze1, wze2, wpe1, wpe2 then 1) I do not need to define any freq, 2) I do not need to vectorize anything and 3) the graphs are displayed. Do you know an explanation for this thing?

 

CornelBejan_1-1665746884963.png

 

CornelBejan_2-1665746927570.png

 

CornelBejan_5-1665746965287.png

 

And do you know how to put grid on the graphs in Mathcad Prime 7?  Can you tell me how to do this?
Grid like:

BodePaper2.gif

Thank you.

 

 

 

LucMeekes
23-Emerald III
(To:Cornel)

The native plot function of Prime does not provide for Grids. But you can make your own.

Attached sheet contains a utility.

 

The reason that the plot works when you strip all units, is because freq, if undefined, gets an automatic range but without units. (The automatic range is -10 to 10 for linear scales, and appears to be 0.4 to 10 for log scales.)

Having units in your omega's but not in your s's causes inconsistent units in the transfer function Gtest, where you add 1 (no units) to s/omega, and only omega has a unit. You're trying to add apples to pears...

 

Success!
Luc

Fred_Kohlhepp
23-Emerald I
(To:Cornel)

Luc beat me to the reply and gets (at least partial) credit for the gridlines.  See attached Prime 7 file

Cornel
19-Tanzanite
(To:LucMeekes)

Why units are not simplified after division with respective units (1V, 1H, 1F, 1ohm), and therefore the obtained expression being without any units?

 

Capture11.PNG

I want to obtain Gtest(s) without any units even if initially V1, L1, C1, R1 have units.

And then I want to plot the bode plot of Gtest(s)

Capture12.PNG

Capture13.PNG

 

 

ttokoro
20-Turquoise
(To:Cornel)

How to use complex frequency s is important. You can use 1j*2*pi*freq instead s. 

 

image.pngimage.png

Cornel
19-Tanzanite
(To:ttokoro)

 

Thank you.

Cornel
19-Tanzanite
(To:ttokoro)

Strange thing happens with this substitute (symbolic operator) in Mathcad Prime 7...🤔

CornelBejan_0-1666175454666.png

@ttokoro Can you also upload your worksheet in such a way to be compatible with Mathcad Prime 7? (I think that your worksheet is done in Mathcad Prime 8, but I do not have Mathcad Prime 8. I have only Mathcad Prime 7 at this moment). Thank you.

 

Werner_E
25-Diamond I
(To:Cornel)

There is a severe and very annyoing bug in Prime: Auto-labeling  does very often not work correct , especially with symbolic operations.

If you check your expressions you will see that all "s" are labelled "Variable", but the "s" after "substitute" is labelled "-", which means "automatic". For the symbolic evaluation this is not the same "s" as in the expression and so nothing is substituted.

Solution is to manually label all variables the same - either all "automatic" or all "Variable". Of course in your example label the "s" after substitute to "Variable" is the easiest approach:

Werner_E_0-1666179732868.png

Even though you may globally set the display of the imaginary unit as "j", the symbolics unfortunately ignores that setting and always uses "i".

 

P.S.: I modified ttokoros sheet and attach it here. I think you should be able to open it with your version now.

Cornel
19-Tanzanite
(To:Werner_E)

@ttokoro @LucMeekes @Fred_Kohlhepp 

 

CornelBejan_0-1666356291406.png

CornelBejan_1-1666356507346.png

CornelBejan_2-1666356537035.png

Thank you.

Fred_Kohlhepp
23-Emerald I
(To:Cornel)

Mathcad has always struggled with symbolic evaluation, so much so that I used to preach against using it,  So the symbolic solver creates the correct function, but the "i" it writes is an undefined variable, NOT the imaginary constant you wanted it to be.

If you add one line:

Fred_Kohlhepp_0-1666358536915.png

Then you can get:

Fred_Kohlhepp_1-1666358596490.png

Another option (dangerous IMHO) would be to define the variable:

Fred_Kohlhepp_2-1666358802605.png

 

 

Werner_E
25-Diamond I
(To:Cornel)

Even though the display is ugly looking in Prime, you have to use 1i or 1j (without a space inbetween) for the imaginary unit, not just i or j.

In real Mathcad you have to do likewise, but the expression will be displayed nicer without the "1".

Prime recognizes 1i and 1j likewise and you can set for numeric evaluations how Prime should display complex numbers - with 1i or with 1j or using the versor symbol ...

The symbolic evaluation ignores this setting and will always use 1i.

 

So in your example you should use "...substitute,s=1i*omega.."

Furthermore its not necessary to torn Gain and Phase into functions of omega, unless you need it that way in later calculations.

Werner_E_0-1666361749363.png

 

 

Cornel
19-Tanzanite
(To:Werner_E)

Start to get annoying using this Mathcad Prime... you go crazy how much headache gives you when using symbolic and graphic in Mathcad Prime, while in Mathcad15 they didn't give you such a headache
Those from PTC are making fun of this Mathcad Prime...

Werner_E
25-Diamond I
(To:Cornel)

I agree that working (maybe I should rater say "playing around") with Prime can be quite "funny" (in the sense of annoying, to despair, to freak out,...).

But you can't blame Prime for you using "i" instead of "1i" 🙂

It was the very same in Mathcad 15, too.

Cornel
19-Tanzanite
(To:Werner_E)

@ttokoro @Werner_E @LucMeekes @Fred_Kohlhepp 
Another headache...

CornelBejan_4-1666364624512.png

CornelBejan_5-1666364648949.png

 

 

CornelBejan_8-1666364711279.png


I do not know how to reconcile these units of measurement in Mathcad Prime...they causes headaches...
First I put the w1, w2, w3, w4 with units of measurement, then I removed them so I can plot Bode plot, but it seems that Mathcad Prime doesn't want to simplify properly.

Then:

CornelBejan_3-1666364189097.png

Well, then how to do to display Bode plot in another way?

 

The idea is that I have units of measurement to the components used (like above w1, w2, w3, w4) and then those components put them in a function of s (like above Gtest(s)) and then I want to display Bode plot for this function in Mathcad Prime 7. In Mathcad15 you didn't have that much trouble if you wanted to do that.

Werner_E
25-Diamond I
(To:Cornel)

Oh yes, thats "funny". Prime's symbolic is confusing unit second with variable s.

But here PTC provides a cure. This very often does NOT help with using units and symbolics, but in your case it does - at least partially!  You have to turn on the option "Using Units and Constants in Symbolic" in the Calculation Options:

Werner_E_0-1666373928370.png

 

Then you must define your function G.test not dependent on "s" (there is no "s" in the final substituted expression) but rather make it a function of "omega". And because the symbolic still has its problems you have to take care that ALL occurrences of the variable "s" are labelled the very same. Most of your "s" are already labelled as "Variable" and it was only necessary to manually label the "s" in the substitute modifier:

Werner_E_1-1666375288999.png

Its not necessary to manually make the conversion from rad to degree when you define Phase. Simply let the unit placeholder in the plot do the job!

Its also not necessary to make omega.1, etc. unitless. Using units should be one of the most benefits when using Prime. You also should apply the proper unit (Hz) to the vector "freq".

Also I guess you should use a log scale on the abscissa in the plots and maybe use "freq" on the abscissa instead of "omega".

 

According NOT making "Gain" and "Phase" functions - just look at the picture in my previous post. I also did it here so you may look at the attached worksheet as well.

"logspace" creates a vector (not a range) and so omega is a vector, too. "Gain" (no function, just a variable) is now calculated from the vector omega by using vectorization. That way "Gain" is a vector, too. So the plots simply plot one vector over the other instead of a function over a range or vector.

Werner_E_3-1666375815277.png

 

 

 

ttokoro
20-Turquoise
(To:Werner_E)

The one with grid.

Cornel
19-Tanzanite
(To:Werner_E)

@ttokoro 

 

Thanks for your answers so far.

It seems, at least so far from what I see, that it must be pressed = to display the adequate results after we have divided with those units of measurement to destroy the units of measurement respectively.

CornelBejan_3-1666600221924.png
To

CornelBejan_0-1666599989013.png

CornelBejan_1-1666600007999.png

 

Now the new problem is why I can not change the values on the Y axis (see the below red circle) of the Phase plot graph, and why Phase plot is not displayed properly, from what it seems. Gain plot is fine, according to and with the previous results posted by you.

CornelBejan_2-1666600068754.png


And why I can not display in the both graphs, Gain plot & Phase plot, the starting value for X axis from as much as I want, for example not to start from 0 Hz (rad/s) but from 10 ^-5 Hz (rad/s) (the graph seems to start at the value 0 even if I change the value). The end value of the graph I see that I can change, i.e. if I change from 65 Hz (rad/s) to 100 Hz (rad/s) then the graphs are expanded up to 100 Hz (rad/s), and that is fine, but for the beginning value of the graph even if I change the value from 0 Hz (rad/s) to 10^-5 Hz (rad/s) then the graphs starts all from 0 Hz (rad/s). Why?

CornelBejan_4-1666601089254.png

 

CornelBejan_7-1666601231545.png

 

CornelBejan_9-1666601293932.png

 

CornelBejan_10-1666601324887.png

Thank you.

 

ttokoro
20-Turquoise
(To:Cornel)

See my worksheet.

ttokoro
20-Turquoise
(To:ttokoro)

image.pngimage.pngimage.pngimage.png

Werner_E
25-Diamond I
(To:Cornel)

I don't understand why you insist on removing units and use G and freq unit-less. Being able to use units in our calculations is one of the strengths of Prime. I also think that its not a good idea to turn angle value into degree by multiplication with 180/pi instead of using the unit placeholder to do the job.

Just my 2 Cents worth, haven't looked in your sheet as I guess/hope that ttokoro already provided solutions for your new problems.

Cornel
19-Tanzanite
(To:Werner_E)

Cornel
19-Tanzanite
(To:Werner_E)

@ttokoro @LucMeekes 


Case 1 - OK

CornelBejan_0-1668166383418.png

CornelBejan_0-1668166954637.png

CornelBejan_3-1668165734411.png

 

Case 2 - NOT OK because of that error: "Unknown error"

CornelBejan_1-1668166807980.png

CornelBejan_0-1668166954637.png

CornelBejan_2-1668165704853.png


Case 3 - NOT OK because of: "These units are not compatible". And if the units had been compatible even in this case, then where would I have been sure that the multiplications/computations for s, w, i and the numbers are doing well, and would not appear some error as in case 2 or the calculations of the numbers in the expression will be not ok?

CornelBejan_2-1668166499294.png

CornelBejan_0-1668166954637.png

CornelBejan_5-1668165793225.png

CornelBejan_8-1668165904134.png


Thank you.

Mathcad Prime 7 attached.

Werner_E
25-Diamond I
(To:Cornel)

ad Case 2: You found a bug in the "new" symbolic engine. You may consider reporting it to PTC support.

Here is what the legacy symbolic engine (available up to Prime 6) returns:

Werner_E_0-1668168792885.png

Maybe someone here with Prime 8 can check if the bug still is present in the current version.

 

 

ad Case 3: Prime is perfectly correct about the unit mismatch. Look at the expression here:

Werner_E_1-1668168857802.png

The first summand 1 is dimensionless but the second is of dimension time^-1

 

squaring omega.4 corrects this but because of the bug in the symbolics it only works in Prime6 when we switch back to the old symbolic engine.

Werner_E_0-1668169270856.pngWerner_E_1-1668169591462.png

 

 

Werner_E
25-Diamond I
(To:Werner_E)

As I see it you have three options to work around that bug in the symbolic engine:

1) Do the substitution manually yourself by defining the function with omega instead of s.
Don't be tempted to use the symbolic "simplify" here as this again would invoke the bug. But you can use a symbolic evaluation with "factor" or "expand" which does not invoke the bug (crazy!).

Werner_E_2-1668170641081.png

Werner_E_4-1668171544493.png

 

2) Do not use units. I tried and it worked OK. But this definitely is not the recommended option.

 

3) Make the symbolic operation before you define your variables and redefine the function later. I would go for this option.

Werner_E_3-1668170854681.png

 

 

Werner_E
25-Diamond I
(To:Werner_E)

I played around and traced back the bug up to a very simple example.

The first factor must be a float number (hence 1.0 and not simply 1)

The second one can be any unit. In the example I used inch, in your sheet it was the seconds

The third factor can be any variable.

The bug shows up only when the exponents of the unit and the variable are equal and if its an odd number greater than 1.

 

Werner_E_5-1668172806854.png

Maybe this helps if you are about to report the bug.

 

Announcements

Top Tags