Community Tip - You can change your system assigned username to something more personal in your community settings. X

Translate the entire conversation x

Programming block matrix, NaN

MI_13148469
3-Newcomer

Programming block matrix, NaN

Hello, I can't solve my problem. I opened a programming block and inserted a matrix to make it faster instead of clearing equation by equation. The values I want to have are A_x and so on. I give M as input data. Help

ACCEPTED SOLUTION

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

I am not sure what your question is.

You may clarify and also attach your new worksheet.

Some remarks about what I notice in your pictures:

The many arguments for your function "fuerzas" do not make any sense because they are not used in any way in the function.

The only argument uses is M and so it should be the only argument of that function. The other arguments have no effect whatsoever!

 

Furthermore I see no reason for assigning the result of "lsolve" to a local variable "z" as this variable is not used anymore. Furthermore the command "augment(z)" has no effect.

 

You must be aware that the variables you define and change inside a program are not connected to worksheet variables with the same name. The only way to change a worksheet variable is via the return value(s) of the function when you assign the function result to worksheet variables when calling the function.

The result of a function is either the value(s) used in an explicit "return" statement or the result of the last command executed in the program.

 

In case of M <> 0 the last command executed is "augment(z)" which should be replaced simply by the "lsolve" command (without z and augment) and so the result of your function is the vector returned by the "lsolve command". When you call the function you  have to save this result vector to worksheet variable(s). You can do as you did with your position, velocity and acceleration function by first assigning the result vector to one variable and then in a second step extract and assign the variables Ax, etc from this. But as already written I think its much easier to directly assign the function result to a vector with the desired variables as shown in the pics.

 

In case of M=0 the last command executed in the program is F <- "no ..." so the function result is this string. There is no need to assign it the local variable F - this assignment has no effect at all.

But if you do so and call the function in the way I suggested

Werner_E_0-1743355527260.png

you would get an error message because you can't store a single string text to a vector with nine variables.

 

View solution in original post

8 REPLIES 8
Werner_E
25-Diamond I
(To:MI_13148469)

1) You created unintentionally a lot of 1x1 matrices which caused errors/NaN's in subsequent calculations. Reason is that you used the columns selector to extract single values and not matrix indices. A column selector will always return a nx1 column vector - in your case a 1x1 vector/matrix.

 

2) Your function "fuerzas" should only have one argument (the input value M) and you forgot to return the desired solution (z).

 

See corrected worksheet attached

I can't open it, it appears: this file is not compatible with its version of mathcad because it has been created with a more recent version of mathcad. I have the mathcad prime 9

Werner_E
25-Diamond I
(To:MI_13148469)

Its necessary to say clearly which version of Prime you are using when asking a question here - if you don't do so, its assumed that the latest current version is used (10.0.1.0 at the time of this writing). Unfortunately PTC has decided that the file format should change with every release each year, that older version should not be able to open newer sheets and that no version should be able to save in an older format (losing newer features, of course). This is stupid, but part of PTC's plan to milk the cow in the best possible way while minimising its own efforts. Development speed of Prime is so slow that changing the file format each year is not justified and saving back in older format could easily be implemented, provided the will to do so would be there.

 

Here are screenshots of the vital parts I changed in your sheet so you can redo it yourself:

Its not necessary to store the result of function "posiciones" in a variable P and then pull out each of the three values one by one.

You can store the results of that function directly in the desired variables.

The same applies to the other two functions for velocity and acceleration.

Werner_E_0-1743351947844.png

 

Werner_E_1-1743351998707.png

 

Werner_E_2-1743352053550.png

 

Werner_E_3-1743352135141.png

 

Werner_E_5-1743352259205.png

 

In case you have troubles applying the necessary changes, come back here and add your edited sheet.

Good luck!

 

 

 

 

 

If you can correct the above now my question would be if I can work in the following way the last block attached images. What I want is to make each variable (M, Axe, etc.) in a single programming block. Could or should a block be made for each variable?

MI_13148469_0-1743352901906.png

MI_13148469_1-1743353137675.png

MI_13148469_2-1743353173246.png

 

 

Werner_E
25-Diamond I
(To:MI_13148469)

I am not sure what your question is.

You may clarify and also attach your new worksheet.

Some remarks about what I notice in your pictures:

The many arguments for your function "fuerzas" do not make any sense because they are not used in any way in the function.

The only argument uses is M and so it should be the only argument of that function. The other arguments have no effect whatsoever!

 

Furthermore I see no reason for assigning the result of "lsolve" to a local variable "z" as this variable is not used anymore. Furthermore the command "augment(z)" has no effect.

 

You must be aware that the variables you define and change inside a program are not connected to worksheet variables with the same name. The only way to change a worksheet variable is via the return value(s) of the function when you assign the function result to worksheet variables when calling the function.

The result of a function is either the value(s) used in an explicit "return" statement or the result of the last command executed in the program.

 

In case of M <> 0 the last command executed is "augment(z)" which should be replaced simply by the "lsolve" command (without z and augment) and so the result of your function is the vector returned by the "lsolve command". When you call the function you  have to save this result vector to worksheet variable(s). You can do as you did with your position, velocity and acceleration function by first assigning the result vector to one variable and then in a second step extract and assign the variables Ax, etc from this. But as already written I think its much easier to directly assign the function result to a vector with the desired variables as shown in the pics.

 

In case of M=0 the last command executed in the program is F <- "no ..." so the function result is this string. There is no need to assign it the local variable F - this assignment has no effect at all.

But if you do so and call the function in the way I suggested

Werner_E_0-1743355527260.png

you would get an error message because you can't store a single string text to a vector with nine variables.

 

What is wanted is that from a value the other unknowns are found (Ax, Ay, etc.) as well as in the previous blocks (speed and position) only that now matrices are used. The idea is to put "forces (0,0,7,0,0,0,0,0,0)" and find the other 8 unknowns. Or should I make the block that you told me independent for each variable?. Because making a programming block for each variable is very tedious, I would have to do the same as you suggested for "forces (M)"

Werner_E
25-Diamond I
(To:MI_13148469)

The calculation you provide does NOT USE  Ax, Ay, etc. so why do you want to make these variables arguments of your function?

I also do not understand which other forces you want your calculation dependent on.

Your calculation is dependent an all the variables you see in this picture:

Werner_E_0-1743367991878.png

And all of these variables with the only exception of M are already predefined and have their constant value. So all you have to provide to make the calculation work is the value of M.

I can't see any variable Ax, By or the like and I thought that these would be the variable names of the results.

Furthermore you could delete the last row and last column in matrix v as well as the last element (M) in vector n as these only assure that the last variable in the result vector is M again. As you provide M yourself it should not be necessary to "calculate" M again.

 

I also do not understand the second calculation with i and j which you added in case F<>0.

This calculation seems to do the very same as the previous one (the value of M is used in the third element of j) and the only reason if F<>0 would be the the last value in the result vector is not the value of M but rather the value of F. Doesn't make sense to me.

 

LucMeekes
23-Emerald III
(To:Werner_E)

Werner's file converted to Prime 9 is attached.

 

Success!
Luc

 

Announcements

Top Tags