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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

stack option

rizz12
10-Marble

stack option

Hi, I was trying to stack all the x coordinates together and all y coordinates together. I see an additional value (0,0) in the result w and v. Can you please tell me why is the additional rows generated and how to eliminate it. And i am using mathcad 15

Thank You.

ACCEPTED SOLUTION

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

Can't see your sheet...
Maybe because you started indexing at 1, while the default start index is 0?

Luc

P.s. you don't need to zip your file.
Mcd, mcdx and xmcd files can be readily attached. To attach several files, edit your post.

View solution in original post

20 REPLIES 20
LucMeekes
23-Emerald III
(To:rizz12)

Can't see your sheet...
Maybe because you started indexing at 1, while the default start index is 0?

Luc

P.s. you don't need to zip your file.
Mcd, mcdx and xmcd files can be readily attached. To attach several files, edit your post.
Werner_E
25-Diamond I
(To:rizz12)

Luc is using Mathcad 11 and so he can't read your file. With MC15 you can resave the file in MC11 format, though (something which is not possible with Prime). I attach the file in MC11 format here.

Attaching the worksheet usually is a good idea and quite often simply necessary. But its also a good idea to attach a screenshot, too 😉

Lucs guess was correct. The setting of ORIGIN in your sheet is the default value 0, so every vector starts indexing with number zero. You created a range variable j which started at 1 and assigned values. So vector element with number 1 gets the correct value 4.5 in, but there still exists a vector element with number 0. This is not assigned a value and so its set to zero by default.

To display the vector y.a you typed y.a[j= which only gives you the elements defined by range j, but not the full vector. If you simply type y.a= you see the full vector with the leading zero.

Rule: If you use a range variable to define vector this range should start with the value of ORIGIN.

Here a small example to demonstrate what happened:

clipboard_image_1.png

 

rizz12
10-Marble
(To:Werner_E)

Thank you for the explanation i was trying to eliminate the set of coordinates which are repeated. They coincide with the vertices of the rectangle, by starting the index j from 1 i wanted to eliminate the repetition. can you suggest me a way to remove Capture2.PNG the repeated coordinates?

 

Thank you

Werner_E
25-Diamond I
(To:rizz12)

Note sure what you mean. Which vertices, which rectangle?

Do these changes address your problem?

clipboard_image_0.png

rizz12
10-Marble
(To:Werner_E)

Thanks for the idea it helped me get what i needed. When i changed the value of m=0,1,2 the j value becomes undefined. so can i give "if" command to consider e and f  instead of w and v if the m is given less than 3??1.PNG2.PNG

 

Werner_E
25-Diamond I
(To:rizz12)


@rizz12 wrote:

Thanks for the idea it helped me get what i needed. When i changed the value of m=0 the j value becomes undefined. so can i give "if" command to consider e and f  instead of w and v if the m is given 0??

 


You get the error because when m=2 you try to use a vector index of -1 (m-3). You can't use a vector index lower than the value of ORIGIN (which is 0).

I guess you could use something with an if construct when you create xp,  but I have the feeling that the vectors you are after (guess they are lists of coordinates ?) can be calculated much easier than the way you try to do it. But unfortunately I have no clue what exactly you are trying to do, maybe you'd like to explain in more detail.

Are you trying to get a list of the m x n coordinates if you divide a l x b rectangle into (m-1) x (n-1) smaller rectangles? But if thats what you are after then n=4 and m=3 should give you a vector with 12 coordinates, not just 9. So maybe you are looking for something else.

 

 

rizz12
10-Marble
(To:Werner_E)

the coordinates are the bolt location. i am trying to calculate the forces on them. based on the formulas i have given earlier some coordinates were coinciding. so i was trying to eliminate them. if m is less than 3 the j becomes undefined and stops the calculation. so i was trying to use e and f function by using if statement in case if m<3 and want to make the j index terms zero.2.PNG3.jpeg

Werner_E
25-Diamond I
(To:rizz12)

Guess I got it.

I would prefer to write a more generic function to do the job:

clipboard_image_0.png

 

Mathcad 15 worksheet attached

Werner_E
25-Diamond I
(To:Werner_E)

Think it would be better if the functions returns a 2-column matrix instead. Your choice anyway.

clipboard_image_0.png

rizz12
10-Marble
(To:Werner_E)

that was really amazing. i have been trying it from so long and couldn't finish it and the code you have given is so short too.Thanks alot. 

after spending so much time on it, i think i should still finish the problem the way i started.

Werner_E
25-Diamond I
(To:rizz12)


@rizz12 wrote:

that was really amazing. i have been trying it from so long and couldn't finish it and the code you have given is so short too.Thanks alot. 

after spending so much time on it, i think i should still finish the problem the way i started.


This will be difficult or even impossible without any programming. You can't use an if-statement where xp is used somewhere, because this statement must fail if the calculation of xp failed.

So you would have to use an if already when you define xp but as you define it by writing xp[j:=... the assignment already fails because of the wrong index j before any if can do its job.

rizz12
10-Marble
(To:Werner_E)

i will try it out once if not I can use your program. thank you. When i take the z= tan inverse it converts the angle from -90 to 90 range. how can i have the angle based on the coordinate location.

Thank you.

 

Capture3.PNG

Werner_E
25-Diamond I
(To:rizz12)


@rizz12 wrote:

i will try it out once if not I can use your program. thank you. When i take the z= tan inverse it converts the angle from -90 to 90 range. how can i have the angle based on the coordinate location.

Thank you.


Try to use     z:=atan2(w,v)    instead of       z:=atan(v/w)

This should give you values in the range from -pi to pi.

 

atan2 has established itself and is available in many programs (eg Excel) and programming languages. Caution must be exercised in the order of the arguments. In MathCad and Excel, the x-coordinate is passed as the first argument and the y-coordinate as the second one, in programming languages such as C or Java it is just the opposite.

 

rizz12
10-Marble
(To:Werner_E)

Thank you, it worked.

rizz12
10-Marble
(To:Werner_E)

hi, W works when i give values greater than 2. Is there anyway we can make W  work if m<3 by giving conditions the j indices values xp,yp,xq,yq = 0 when m<3.

 

thank you

Werner_E
25-Diamond I
(To:rizz12)

Your approach only works if xp and xq are valid variable which have been assigned a value.

Fortunately there is a simple solution. You have to make sure that the definition of xp and xq does not fail and so you have to avoid that the range j runs into a value below ORIGIN (0). You only have to define the range j a little bit different:   j := 0 .. max(0, m-3)

In this case, when m<3, j becomes a range from 0 to 0, which is valid also for indexing a vector. And your if statement later makes sure that in the case of m <3, the unnecessary values of xp and xq are not included in the vector W.

You may also use the if-function instead, even though its not that clear in display: W:=if(m<3, stack(xa,xb), stack(xa,xb,xp,xq)). Guess its a matter of personal taste - I'd prefer the way you did it.

 

rizz12
10-Marble
(To:Werner_E)

Thank you. It works perfectly and got to learn new things.

rizz12
10-Marble
(To:Werner_E)

hi,can you tell me How did you position the coordinates as points instead of the connecting lines for the coordinates (W,V)? and can the point indicate which bolt its referring to?

 

 

Werner_E
25-Diamond I
(To:rizz12)

Double click the plot (or  chose from the menu Format-Graph-XY-Plot), select Tab "Traces" and under "type" chose "points" instead of the default "lines". Then you may chose a "symbol" and its size (-> "Symbol Weight").

rizz12
10-Marble
(To:Werner_E)

thank you.

Announcements

Top Tags