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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Translate the entire conversation x

Making mathcadfile look more complicated

XV_10815251
4-Participant

Making mathcadfile look more complicated

So a few days ago i made a post of my graphs not working. 

Back then i asked 3 teachers to look at it but they all couldn't solve it. Luckly the ptc community could.

But now i need to present the solution and i want to add fancy things so it looks more complex then it is.

For example first check of something is a range but somehow my second value wont work for it.

Any other idea's to make it look more complicated?

XV_10815251_0-1766837326696.png

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:XV_10815251)

Prime alerts you that you are misusing a range, using it for something it is not intended for.
A range is not a collection of values like a vector (even though Prime unfortunately displays them the same way). A range rather is an instruction, kind of an implicit loop.

 

A range can/should be used for

1) indexing the elements of vectors and matrices
2) creating a for-loop in a program

3) making plots

 

So using a range as a function argument is perfectly OK when creating a plot

Werner_E_0-1766854952376.png

and Prime even is willing to display the values calculated (which may be misleading...)

Werner_E_1-1766854986777.png

but what this function call actually creates is not a valid data structure recognized and accepted by Prime.

You experienced this when you tried to use "IsRange" and you get the very same error message if you simply try to assign it  to a variable

Werner_E_2-1766855155105.png

The right hand side simply is treated as an invalid data structure to Prime which it refuses to use - its not a scalar, not a vector and also not a range.

And IsRange(ϕ) sure must return 0 because its not a range but rather a function 

Werner_E_0-1766858053813.png

 

So use ranges just for what they are intended for and vectors for the rest. And no, you are by no means the first person to stumble over this difference between ranges and vectors, and you certainly won't be the last. I guess it's happened to all of us at some point, and it's an age-old pitfall.

 

So to create something like a table of values you should use vectors.

 Starting with Prime 11 we have a convenient function "vec" to do so.

Werner_E_3-1766855507801.png

The three function arguments are the same as you used for creating the range.

One word of caution because you named the second value θ.1stap. In a range definition and also in "vec" this second value is NOT the desired step width, but rather the second value in the list created. Its identical with the step width only if the first value is zero!

 

"vec" creates a true vector (or more general a matrix or an array)

Werner_E_6-1766856208556.png

Now you an use this vector as argument of your function

Werner_E_4-1766856061899.png

and the result is a valid data structure, a vector (matrix,  array)

Werner_E_5-1766856135699.png

One word of caution: You should vectorize the function call whenever you use a vector as argument of a function which is written for scalar arguments. Its not necessary in case of your function, however, it is best to get into the habit of always vectorizing in such cases, as this saves you from having to check whether it is necessary in each specific case.

An example: The three functions f1, f2 and f3 seem to be identical, doing the very same

Werner_E_8-1766856985820.png

But when you provide a vector of values as function argument, you see differences

Werner_E_9-1766857043642.png

Reason is that in f2 and f3 the first multiplication is done with two vectors now and Prime of course has to use vector multiplication (dot product, scalar product) here.

So I got into the habit of applying always vectorization when I feed a vector into a scalar function, not having to think about if it would be really necessary or not:

Werner_E_10-1766857223147.png

 

 

In your sheet you could now create tables or whatever you had in mind

Werner_E_11-1766857553081.png

 

You may also consider using a range phi with a smaller step width to make for smoother plots and a vector phi with less values for the tables. And you don't have to define that range/vector right on top of the sheet as you had done, but rather right in front of its first use (plot, table, ...)

 

And of course you could also use vectors for plotting even though ranges are made for it and may feel more natural to be used in plots.

Werner_E_12-1766857858275.png

 

 

 

View solution in original post

5 REPLIES 5
LucMeekes
23-Emerald IV
(To:XV_10815251)

Probeer eens

LucMeekes_0-1766838574423.png

dus zonder 

LucMeekes_1-1766838636294.png

 

Succes!

Luc

XV_10815251
4-Participant
(To:LucMeekes)

Dag Luc,

Dan zegt het 0, dit betekend volgens mij dat het geen range is. kan ik dan op een manier zien wat het wel is?

LucMeekes
23-Emerald IV
(To:XV_10815251)

D'r zijn nog meer IsXxx functies: IsScalar, IsArray, IsString...

Er is geen WhatIs functie.

 

Success!
Luc

Werner_E
25-Diamond I
(To:XV_10815251)

Prime alerts you that you are misusing a range, using it for something it is not intended for.
A range is not a collection of values like a vector (even though Prime unfortunately displays them the same way). A range rather is an instruction, kind of an implicit loop.

 

A range can/should be used for

1) indexing the elements of vectors and matrices
2) creating a for-loop in a program

3) making plots

 

So using a range as a function argument is perfectly OK when creating a plot

Werner_E_0-1766854952376.png

and Prime even is willing to display the values calculated (which may be misleading...)

Werner_E_1-1766854986777.png

but what this function call actually creates is not a valid data structure recognized and accepted by Prime.

You experienced this when you tried to use "IsRange" and you get the very same error message if you simply try to assign it  to a variable

Werner_E_2-1766855155105.png

The right hand side simply is treated as an invalid data structure to Prime which it refuses to use - its not a scalar, not a vector and also not a range.

And IsRange(ϕ) sure must return 0 because its not a range but rather a function 

Werner_E_0-1766858053813.png

 

So use ranges just for what they are intended for and vectors for the rest. And no, you are by no means the first person to stumble over this difference between ranges and vectors, and you certainly won't be the last. I guess it's happened to all of us at some point, and it's an age-old pitfall.

 

So to create something like a table of values you should use vectors.

 Starting with Prime 11 we have a convenient function "vec" to do so.

Werner_E_3-1766855507801.png

The three function arguments are the same as you used for creating the range.

One word of caution because you named the second value θ.1stap. In a range definition and also in "vec" this second value is NOT the desired step width, but rather the second value in the list created. Its identical with the step width only if the first value is zero!

 

"vec" creates a true vector (or more general a matrix or an array)

Werner_E_6-1766856208556.png

Now you an use this vector as argument of your function

Werner_E_4-1766856061899.png

and the result is a valid data structure, a vector (matrix,  array)

Werner_E_5-1766856135699.png

One word of caution: You should vectorize the function call whenever you use a vector as argument of a function which is written for scalar arguments. Its not necessary in case of your function, however, it is best to get into the habit of always vectorizing in such cases, as this saves you from having to check whether it is necessary in each specific case.

An example: The three functions f1, f2 and f3 seem to be identical, doing the very same

Werner_E_8-1766856985820.png

But when you provide a vector of values as function argument, you see differences

Werner_E_9-1766857043642.png

Reason is that in f2 and f3 the first multiplication is done with two vectors now and Prime of course has to use vector multiplication (dot product, scalar product) here.

So I got into the habit of applying always vectorization when I feed a vector into a scalar function, not having to think about if it would be really necessary or not:

Werner_E_10-1766857223147.png

 

 

In your sheet you could now create tables or whatever you had in mind

Werner_E_11-1766857553081.png

 

You may also consider using a range phi with a smaller step width to make for smoother plots and a vector phi with less values for the tables. And you don't have to define that range/vector right on top of the sheet as you had done, but rather right in front of its first use (plot, table, ...)

 

And of course you could also use vectors for plotting even though ranges are made for it and may feel more natural to be used in plots.

Werner_E_12-1766857858275.png

 

 

 

XV_10815251
4-Participant
(To:Werner_E)

Thank you for sharing your knowledge; I can now give a proper explanation to my teacher.

Announcements

Top Tags