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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

How to set ranges of variables in a plot in Mathcad prime

Huy_Nguyen
4-Participant

How to set ranges of variables in a plot in Mathcad prime

Hi. I am trying to set ranges of variables in a plot in Mathcad prime v.7.0. But it is really difficult for me. Can you give me some advice? Thank you so much.

Huy_Nguyen_0-1664183452543.png

 

Huy_Nguyen_1-1664182378634.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Your goal is to limit the lines to duplicate the picture, right?

It may be possible doing so with a couple of range variables (I guess you would need four different ranges to accomplish the task), but I find it more comfortable to define new functions using the if-function to "plot" NaNs where you don't want to see the line.

I added Eq1 which was missing in your plot.

Werner_E_1-1664190496389.png

 

EDIT: Just for fun I added a way to achieve the same plot using four ranges.

 

View solution in original post

9 REPLIES 9

Your goal is to limit the lines to duplicate the picture, right?

It may be possible doing so with a couple of range variables (I guess you would need four different ranges to accomplish the task), but I find it more comfortable to define new functions using the if-function to "plot" NaNs where you don't want to see the line.

I added Eq1 which was missing in your plot.

Werner_E_1-1664190496389.png

 

EDIT: Just for fun I added a way to achieve the same plot using four ranges.

 

Huy_Nguyen
4-Participant
(To:Werner_E)

That's great. You made it really nice with 2 different ways, specially 2rd way. Thank you so much.

Old-MCAD-User
5-Regular Member
(To:Huy_Nguyen)

Just be careful not to evaluate the range variable, I have a bug where when I end the range variable for evaluating its array, it crashes everything below it related to it, including graphs. I can evaluate it separately and it works, but it shouldn't have to be separated. I have also run into problems with units in range variables causing similar issues. I am on Prime 7.0, unfortunately. I'm not a fan of any of the Prime series based on the hundreds of bad conversion crashes my converted MathCAD v15 and prior are causing. All other prior MathCAD versions work just fine when evaluating with an "=" sign after a range variable. Only Prime crashes. 

I am not sure what you problem is!? What your "before" pic is showing would not work in real good old Mathcad as well!

A numerical evaluation of a function definition is not allowed - for good reasons!

You should also be aware that if you define a range and follow that definition by a numerical evaluation, as you did when you defined "t", the range is turned into a vector! This is an undocumented feature and works the same in Mathcad 14/15 as well as in Prime.

That said you also should be aware that the results you get when you evaluate y(t) are NOT the results you might expect!

Because t is now a vector, e^-t is a vector, too, and the same applies to cos(5t). These two vectors are now multiplied and the result is a SCALAR (vector product)! This scalar is now multiplied with cos(10t) which again is a vector and thats the reason you get a vector result, but with values you did not expect.

The get the correct results you would have to apply vectorization when you call y(t).

 

You will see the very same behaviour in Mathcad 15, 14 as in Prime in this case.

So, no, this is not a bug, but just a matter of misunderstanding how Mathcad and Prime are working and dealing with ranges and vectors.

Werner_E_0-1664383199927.png

 

Old-MCAD-User
5-Regular Member
(To:Werner_E)

The images were intended to show that you cannot put the = sign after the definition or it would fail. Trying to help someone so they didn't get hung up on that same issue.

 

It makes no sense that it cannot evaluate what it can evaluate immediately after a function definition. It still evaluates it after having typed it, so to a user this makes no sense that it can be queried immediately after the function definition vs. after the function definition. 

 

I see that it doesn't work in v15, now, but I see so many other things that don't work from v15 to Prime that this looked just like another one of the failed conversions that it's mixed up with the plethora of other conversion problems.

 

You could stand to tone down your attitude with me trying to help someone else. This is the first post I make and already getting attitude from you isn't a good start for someone who has hundreds of old worksheets destroyed by the conversion process and getting no help from support.

It looks to me that you mix up formal and actual argument of a function. Its the same in Mathcad/Prime as its in pure Math (and also similar to function definitions in most program languages.

If you look at the simple example below, x in the function definition f(x):=... has nothing to do with the x defined before. Its just the formal argument in the definition of the function and it would work the same if you use a different argument name here as can be seen in the second picture.

On contrary the x in the evaluation is the actual/current function argument and Mathcad uses the variable with that name when you evaluate the function or will give you an error if no variable x is defined.

Look again at the second where I used "t" as formal function argument. If you would put an eval equal sign after the definition, why should Mathcad use the variable "x" here? Formal function arguments can be named as you like and have no connection whatsoever with variables of the same name defined elsewhere.

Werner_E_0-1664387935368.png

---------------

Werner_E_1-1664387957075.png

 

Concerning your criticism about Prime I fully agree, though. Its a shame that 15 year old Mathcad still is superior over its successor(?). Prime is slower, more awkward to handle is missing a lot of features available in old Mathcad and when it comes to plotting ... OMG!! And Prime sure has its bugs, but what you showed is not a bug, its normal behaviour even though you seem to find it not intuitive.

Old-MCAD-User
5-Regular Member
(To:Werner_E)

Thanks for your reply, I typically have only used algebraic equations, range variables, graphing, derivatives and integrals.

 

For most of my other needs I use other software packages to further process the data (OriginPro, for example). 

 

The issue I found when you responded the first time helped identify that my previous worksheets where I typically asked for the evaluation of the range variable, along with the actual variable was from older versions before the = sign was allowed to be used at all.

 

I have been using MathCAD for ~27 years, so I typically only use it for the above basic functions, most notably, units calculation which was seriously damaged on my converted worksheets.

 

I have been used to the attached image for the issue I was having trouble with, because I was used to doing it the old way (v15 and prior).

 

It mixed the two images up, but on the left is what I started doing when they allowed the = sign to be done after the range variable. In my original reply, I mis-typed 'range variable' when I should have put the 'function' using the 'range variable', as I later realized. Below you can see how I now have been using the range variable evaluation, and on the right, the old way I did it to get an X, Y type of comparison next to each other. 


I understand the mathematical difference of the variable vs. function, I had just done it more recently on new worksheets evaluating the range variable immediately after defining it, so I figured it would allow me to do the same after the function definition, similarly. Now I see my old worksheets had both next to each other but not immediately after the definition like I now do more regularly.

 

Range-Variable-Evaluation.PNGRange-Variable-Evaluation-Old-Method.PNG

 

In the last pic you posted the results of A(t)= .. are correct, because the function A does not have elements where vector arithmetic would be applied and so Mathcad automatically applies implicit vectorization. But I would suggest using explicit vectorization everytime you want it to be done so you are on the save side. As seen in my last example you may get wrong results for some functions if you don't apply vectorization.

Thank you so much. It's a good information to me

Top Tags