Skip to main content
4-Participant
March 30, 2025
Solved

Programming block matrix, NaN

  • March 30, 2025
  • 1 reply
  • 1433 views

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

Best answer by Werner_E

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.

 

1 reply

25-Diamond I
March 30, 2025

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

4-Participant
March 30, 2025

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

25-Diamond I
March 30, 2025

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!