How to use a symbolically evaluated equation for a plot?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
How to use a symbolically evaluated equation for a plot?
I am trying to get a bode plot of a transfer function which I symbolically evaluated first. After that I want to insert some constants and then use it for a bode plot. Is there a way to do that?
I am using PTC Mathcad Prime 10,0.1.0.
Solved! Go to Solution.
- Labels:
-
Mechanical_Engineering
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
There's no problem, in fact it is advisable, to do what you want. You just have to carry the unknowns as parameters in your functions. See here:
Success!
Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
To start, move the definitions for "a" and "b" before your equations where you use those variables. Mathcad doesn't know what they are when the equations are executed. Once you do that, you might find that things are easier to troubleshoot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
The thing is I want to see the symbolic evaluation at first, since this version I've showed in my file is just a simple example. The evaluation I do a is much more unclear than in the example, which is why I need to see it first. Or is it not possible to do it this way in Mathcad?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
You can't do it that way, because Mathcad evaluates your equations line by line from top to bottom and left to right. So, you're trying to evaluate a function that has variables which are undefined. The other issue is that your functions don't evaluate to a result. See the WS3 attached. N(s) and Z(s) don't mean anything because "s" is not defined. It could be a function or a variable. Mathcad doesn't know how to interpret that.
I created new functions N(t) and Z(t), where "t" is defined as mathematic operations of "a" and "b". Those functions evaluate to a result, and so does "g", So you have to define or evaluate every term in your equation. You also used the solve function to evaluate the result of G. You can do that, but you have to define it differently, i.e. you have to state what variable you're solving for. Since "s" is unknown in both equations, G(s) can't be evaluated.
Remember, your inputs, i.e. variables, can also be arrays or vectors. They don't have to be constants like I have used here. But that requires a different way of handling the arithmetic operations in your functions.
Hope that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
You're welcome. Yes, looks like you're on the right track. Good work! Best of luck. Please repost when you have your Bode plot solution. I'm interested to follow your work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
There's no problem, in fact it is advisable, to do what you want. You just have to carry the unknowns as parameters in your functions. See here:
Success!
Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Good to know. Thanks Luc. This helps me as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
And if you think you have to carry too many parameters into a function, you can put them in an array:
Success!
Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you, good to know that it also works this way. These plots look very good. How do you get the continuous function? My functions always just go from frequencies of 200 to 2*10^4 Hz. Also how do you enable the green lines for any plot?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I use a version of (the real) Mathcad from the beginning of this century. Somewhere around 2008 PTC took over and decide they'd make a 'better' product and created Prime. Now, more than 15 years and 10 versions later their product still cannot match up with some aspects of Mathcad (graphing, speed), although in some respects Prime is better (allows multiple units in an array and allows symbolic solving of differntial equations.)
And yes, Prime supports grids in plots, NOT in the native plots, but only in the chart component (a badly integrated third-party add-on that doesn't support units). So with regards to plotting with Prime you have to choose between two evils (or are they a nuisance and an outrage?).
With regard to not plotting a full range of frequencies: you did not define f (me neither), but if you do that, Mathcad (and Prime as well) chooses its own range for it. Apparently Mathcad does a better job.
Now you could define a range for f, but all you can do is define a linear range (you cannot define a log range) and a linear range from 0.02 up to 20000, in steps of 0.02, would create a range of 1 million points. Then Prime will tell you it cannot plot that many points in a graph.
The way out is to define a vector of frequencies. Look at the built-in functions logpts() and logspace(). I prefer my own defined logrange that creates a vector of log spaced values from a begin value to an end value with a set number of points per decade:
So with:
I get F to be a vector (Note that that is different from a range!) of values from 0.01 to 100 000 with 50 points per decade.
Now I need an index to point to all frequencies in that vector, from first to last:
(ORIGIN is a built-in constant, usually 0 or 1, you can set it, that is the index of the first array element. last obviously gives the last index of its argument, which must be a vector, which F is.)
And I can plot:
Still no grid. For that purpose there is e.g. this: https://community.ptc.com/t5/Mathcad/Bode-Plot-NaN-Complex-values-Error-and-Plot-Grid-Does-Not-Exist/m-p/830506/highlight/true#M203237
Success!
Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Additionally to what Luc already explained.
You can also get the plot from 0.01 to 10 if you set the axis limits directly in the plot.
You can edit the first, second and the last value on each axis and most of the time changing the second value is necessary because the values automatically chosen by Prime are ... suboptimal (to say it in a polite way).
If the axis is logarithmically scaled, you can only edit the first and last value and Prime will only chose full decades to plot.
In the picture I highlighted the values you are allowed to edit in your plots.
If you don't edit a value or if you delete a value you entered, Prime will chose a value on its own.
BTW, you sure have already noticed from Luc's picture that you forgot about the factor 2 pi in your file, didn't you?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Prime 10.0.1 If useing logspace function, plot needs vectorization, however, linear range doesn't need.
