Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- working with vectors in a program

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-26-2013
01:28 PM

04-26-2013
01:28 PM

Hi everyone, I'm having lots of issues with one program I'm doing, and I would like to ask if you can help me with one in particular.

I'm trying to pick up a number from a vector compare it with some value and then do an iteration, but for some reason Mathcad doesn't let me pick up the number from the vector.

I'm trying to do:

but it seems that I cannot use this kind of statement in an iteration.

Thx in advance.

PS: I'm Spanish so excuse me if my english it's a little bit rough

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-26-2013
04:59 PM

04-26-2013
04:59 PM

I tried to edit the foregoing post and insert a pic but got repeatedly an error "null" ??

So here it is:

Is this in the range of what you tried to do?

BTW, I think that you felt in the trap of thinking that Mathcad would take the variables which are calculated and defined in the sheet before the routine in some other parts of your routine, too (K22). K23 is OK as you never define a local variable with that name.

13 REPLIES 13

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-26-2013
01:37 PM

04-26-2013
01:37 PM

Re: working with vectors in a program

Not sure what the problem is?

v.return is a matrix consisting of four vectors, each containing 21 3*1 vectors.

Where do you try to pic a number from (which?) vector??

BTW, this

doesn't seem to make any sense!?

Another thing I noticed:

As soon as K1 gets 0 the first time it will never change that value again. Is this what should happen? Or did you had in mind that the local K1 should get the value of the variable K1 outside if the program whenever the condition is fulfilled? In the latter case you would have to rename one of the K1, as Mathcad will always take the "nearest" K1 it will find - tha tis the local one if it exist (which is the case after the first assignment).

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-26-2013
04:41 PM

04-26-2013
04:41 PM

Re: working with vectors in a program

BTW, this

doesn't seem to make any sense!?

no you're right, but this it's only because the program isn't finished yet and I have to figure out a couple of things more.

Another thing I noticed:

As soon as K1 gets 0 the first time it will never change that value again. Is this what should happen? Or did you had in mind that the local K1 should get the value of the variable K1 outside if the program whenever the condition is fulfilled? In the latter case you would have to rename one of the K1, as Mathcad will always take the "nearest" K1 it will find - tha tis the local one if it exist (which is the case after the first assignment).

I thought that Mathcad checks each step if the condition is fullfilled and if it is it takes the first definition of K1 because the vaules of x are changing each step.

Despite all of this, the problem I was talking about was with the definition of Fi+1, I want to make a simple calculus with a scalar number, I mean obtain a diferent value of Fi+1 each step but mathcad tells me that it has to be a matrix, and I don't get it.

THX

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-26-2013
04:51 PM

04-26-2013
04:51 PM

Re: working with vectors in a program

Another thing I noticed:

As soon as K1 gets 0 the first time it will never change that value again. Is this what should happen? Or did you had in mind that the local K1 should get the value of the variable K1 outside if the program whenever the condition is fulfilled? In the latter case you would have to rename one of the K1, as Mathcad will always take the "nearest" K1 it will find - tha tis the local one if it exist (which is the case after the first assignment).

I thought that Mathcad checks each step if the condition is fullfilled and if it is it takes the first definition of K1 because the vaules of x are changing each step.

What do you mean by "first definition"? The one outside of the program? No, it will only take it the very first time the line K1 <--- .... is executed. From then on in the iteration mathcad will take the internal variable K1 anf if this is set to zero in one step, it will stay zero for all succeeding steps. The vector x changes in each step, but why do you think this would affect K1? K1 is not calculated in your routine. It is either set to K1 (which makes sense only the very first time) or set to zero.

Despite all of this, the problem I was talking about was with the definition of Fi+1, I want to make a simple calculus with a scalar number, I mean obtain a diferent value of Fi+1 each step but mathcad tells me that it has to be a matrix, and I don't get it.

But there is no code in your file showing this attempt!? Fi+1 is a 3x1 vector, not a scalar.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-27-2013
04:48 AM

04-27-2013
04:48 AM

Re: working with vectors in a program

Werner Exinger escribió:

Another thing I noticed:

I thought that Mathcad checks each step if the condition is fullfilled and if it is it takes the first definition of K1 because the vaules of x are changing each step.

What do you mean by "first definition"? The one outside of the program? No, it will only take it the very first time the line K1 <--- .... is executed. From then on in the iteration mathcad will take the internal variable K1 anf if this is set to zero in one step, it will stay zero for all succeeding steps. The vector x changes in each step, but why do you think this would affect K1? K1 is not calculated in your routine. It is either set to K1 (which makes sense only the very first time) or set to zero.

Mathcad won't compare each step if xi0-xi1 is >0?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-27-2013
04:57 AM

04-27-2013
04:57 AM

Re: working with vectors in a program

nges in each step, but why do you think this would affect K1? K1 is not calculated in your routine. It is either set to K1 (which makes sense only the very first time) or set to zero.

Mathcad won't compare each step if xi0-xi1 is >0?

Ofcourse it does, but what happens if the condition is fulfilled? K1 is assigned K1!? The K1 to the left of the assignment is a local variable K1. The K1 to the right is ALSO this very local variable!! Mathcad will only grab the worksheet variable calculated before if there is no local variable with the name K1 which is the case exactly one times - the first time the assigment is done. From then on the local K1 is taken for evey K1 in the program and if this is set to 0 it will stay zero for the rest of the routine as it is never assigned a different value. K1 <-- K1 will take the local K1 (which is zero) and assign it to itself - it remains zero.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-28-2013
05:14 AM

04-28-2013
05:14 AM

Re: working with vectors in a program

Ok, Understood.

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-26-2013
04:59 PM

04-26-2013
04:59 PM

I tried to edit the foregoing post and insert a pic but got repeatedly an error "null" ??

So here it is:

Is this in the range of what you tried to do?

BTW, I think that you felt in the trap of thinking that Mathcad would take the variables which are calculated and defined in the sheet before the routine in some other parts of your routine, too (K22). K23 is OK as you never define a local variable with that name.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-27-2013
05:00 AM

04-27-2013
05:00 AM

Re: working with vectors in a program

Werner Exinger escribió:

I tried to edit the foregoing post and insert a pic but got repeatedly an error "null" ??

So here it is:

Is this in the range of what you tried to do?

BTW, I think that you felt in the trap of thinking that Mathcad would take the variables which are calculated and defined in the sheet before the routine in some other parts of your routine, too (K22). K23 is OK as you never define a local variable with that name.

Now I'm really scared, Mathcad desn't use the variables I've defined before the routine?

BTW I could solve the problem with the vector and the scalar thing with that definition.

THx a lot.

And now I've to think what you said about the previously defined variables...

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-27-2013
05:14 AM

04-27-2013
05:14 AM

Re: working with vectors in a program

Now I'm really scared, Mathcad desn't use the variables I've defined before the routine?

Not, if a local variable with the same name exist. It will take the "nearest" variable it finds.

Thats pretty much the same behaviour as with most programming languages

While in some programming languages you can explicitely specify the variable from which context you want to address, in Mathcad thats not possible.

But the solution is simple - just use different variable names.

One thing I haven't mentioned so far is that its inefficient to do the calculation of E.D inside the loop. As far as I can see its not dependent on anything which changes in the iteration so it should be precalculated outside of the loop, maybe even outside of the program.

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-28-2013
09:48 AM

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-26-2013
07:53 PM

04-26-2013
07:53 PM

Re: working with vectors in a program

Now I see it! The picture you provided does not correspond to the file you posted!!

Your problem is that you wanted to do this:

Why is F[i not red in your screenshot?

Mathcad is absolutely right in saying "This value must be a vector".

Lets analyze it:

i=0 Vector F[0 is defined outside of the program as 3x1 vector (all 0), So F[i[0 yields 0 (Newton), K3 is a scalar (kg(s^2) and the calculations of the x[i..[j in the square brackets yield a result which is a scalar, too (m) - so the product is a scalar (in N) and the sum is a scalar (N) which is assigned F[1. Keep in mind: F[0 is a 3x1 vector, but F[1 is a scalar!!!

Now we come to i=1, and that line tries to evaluate (F[1)[2, but F[1 is a scalar and so you cannot access its third component and Mathcad says that it would have to be vector to able to do so - right!

So its not that vector behave differently inside of a program, but rather that you have to take care, that all F[i get a vector as value, not a scalar!

Would something like this do the job?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-27-2013
05:01 AM

04-27-2013
05:01 AM

Re: working with vectors in a program

Werner Exinger escribió:

Now I see it! The picture you provided does not correspond to the file you posted!!

Your problem is that you wanted to do this:

Why is F[i not red in your screenshot?

Mathcad is absolutely right in saying "This value must be a vector".

Lets analyze it:

i=0 Vector F[0 is defined outside of the program as 3x1 vector (all 0), So F[i[0 yields 0 (Newton), K3 is a scalar (kg(s^2) and the calculations of the x[i..[j in the square brackets yield a result which is a scalar, too (m) - so the product is a scalar (in N) and the sum is a scalar (N) which is assigned F[1. Keep in mind: F[0 is a 3x1 vector, but F[1 is a scalar!!!

Now we come to i=1, and that line tries to evaluate (F[1)[2, but F[1 is a scalar and so you cannot access its third component and Mathcad says that it would have to be vector to able to do so - right!

So its not that vector behave differently inside of a program, but rather that you have to take care, that all F[i get a vector as value, not a scalar!

Would something like this do the job?

awesome, absolutely right

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-27-2013
05:17 AM

04-27-2013
05:17 AM

Re: working with vectors in a program

awesome, absolutely right

Really!?? That way the first two components of the 3x1 vectors Fi.. never change - as the WS is written they remain zero.

The code would first copy Fi over to Fi+1 making sure that way, that Fi+1 is a 3x1 vector. Then the third component of this nev vector is changed for the scalar calculated according to your pic.