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
- :
- Re: 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
- Printer Friendly Page

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

Showing results for

- Mark as New
- Bookmark
- Subscribe
- 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

- Mark as New
- Bookmark
- Subscribe
- 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

- Mark as New
- Bookmark
- Subscribe
- 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).

- Mark as New
- Bookmark
- Subscribe
- 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

- Mark as New
- Bookmark
- Subscribe
- 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.

- Mark as New
- Bookmark
- Subscribe
- 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.

- Mark as New
- Bookmark
- Subscribe
- 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?

- Mark as New
- Bookmark
- Subscribe
- 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?

- Mark as New
- Bookmark
- Subscribe
- 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
- 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...

- Mark as New
- Bookmark
- Subscribe
- 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