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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Problems with using function solve blocks

VishnuGopalakri
1-Newbie

Problems with using function solve blocks

Hello All

I am new to Mathcad and I am currently trying to use function solve blocks but i am getting an error that says initial guesses must consist of numbers and matrices. I am not able to figure out where I am going wrong and how to rectify it.I have enclosed my worksheet

1 ACCEPTED SOLUTION

Accepted Solutions

Vishniu Gopalakrishnan wrote:

Hello All

I am new to Mathcad and I am currently trying to use function solve blocks but i am getting an error that says initial guesses must consist of numbers and matrices. I am not able to figure out where I am going wrong and how to rectify it.I have enclosed my worksheet

The good news first: You have used the solve blocks perfectly correct and you also turned them into function without any error.

If you really need all those constants and guess values as arguments of your function you can do exactly like you have done.

The error occurs because in your program you have in the last line T[i <-- N[8. This line turns T into a nested vector of values but your solve block expects T to be a scalar or at least a matrix consisting of just scalars. The error message is misleading here and in no way helpful. So you have to change your routine so that the last argument in the call of sol2 is a scalar (probably the last value in vector T.

Maybe you don't even need to make T (and also theta.2,3,4) vectors? The value in one iteration might as good overwrite the previous one, unless of course you need all values as result. You have not yet decided what the routine should return as rsult for torque. As you have it now it would be the last value N[8 because thats the last assigment made.

The error in greater detail:

  1. i=0: T=0 and the result N[8 is a scalar value. You assign T[0<--N[8 and so T is a 1x1 matrix now
  2. i=1: T=[1x1] and the result N[8 is also a 1x1 matrix. You assign T[1<--N[8 and so T is now a nested vector with two elements - the first is a scalar but the second is the 1x1 matrix.
  3. i=2: T=[scalar; [1x1]] this mixed data structure makes your solve block fail.

While looking at your sheet I found an irregularity which I think applies for a Prime bug. Maybe someone can look over it and report them to PTC support (I won't do so) if appropriate.

  • I played around with the first solve block and the constrained for theta.2 and wondered, why the value of theta.2 is that big when we do not constrain it (picture 1).
  • I wanted to add a similar constraint for theta.3 and first just copied the first constraint which i had now twice. You would expect that this does not change anything, but far wrong - the value of theta.3 changes!!! (pictures 2)
  • I then changed the the second constrain to apply for theta.3, but now the solve block failed. I allowed theta.3 to be in the range from 0 to 2*pi (there sure has to be a solution in that range) but to no avail - that alone would apply as a bug, I think. Then I changed the range for theta.3 to -10^6 to +10^6 but Prime stills does not find a solution!! (picture 3). Even larger ranges may give a result for one or both of my evaluation.

1.png

2.png

3.png

View solution in original post

8 REPLIES 8

I suggest you look up Solve Blocks in the help menu.

You must provide guess values for all unknown variables. The number of equations in the 'constraints' section of the solve block must equal the number unknown variables.

Thank you for the reply Mike.I have a few questions

1.Is it possible to pass guess values as an argument?or do I need to explicitly mention it in the solve block?

2.In the program, A & C are not guess values but actual values that need to be used in the computation and it changes for every interation in the program.Does mathcad recognize that it is that and not a guess value?

Vishniu Gopalakrishnan wrote:

Thank you for the reply Mike.I have a few questions

1.Is it possible to pass guess values as an argument?or do I need to explicitly mention it in the solve block?

Yes you can. Have a look at the attached worksheet for a VERY simplistic example of passing a function to a solve block.

Vishniu Gopalakrishnan wrote:

2.In the program, A & C are not guess values but actual values that need to be used in the computation and it changes for every interation in the program.Does mathcad recognize that it is that and not a guess value?

They can be defined outside the solve block if they need to be used in proceeding calculations.

Thank you so much Mike. I will go through it and will get back if I still have any doubts

Vishniu Gopalakrishnan wrote:

Thank you so much Mike. I will go through it and will get back if I still have any doubts

No problem at all.

Vishniu Gopalakrishnan wrote:

Hello All

I am new to Mathcad and I am currently trying to use function solve blocks but i am getting an error that says initial guesses must consist of numbers and matrices. I am not able to figure out where I am going wrong and how to rectify it.I have enclosed my worksheet

The good news first: You have used the solve blocks perfectly correct and you also turned them into function without any error.

If you really need all those constants and guess values as arguments of your function you can do exactly like you have done.

The error occurs because in your program you have in the last line T[i <-- N[8. This line turns T into a nested vector of values but your solve block expects T to be a scalar or at least a matrix consisting of just scalars. The error message is misleading here and in no way helpful. So you have to change your routine so that the last argument in the call of sol2 is a scalar (probably the last value in vector T.

Maybe you don't even need to make T (and also theta.2,3,4) vectors? The value in one iteration might as good overwrite the previous one, unless of course you need all values as result. You have not yet decided what the routine should return as rsult for torque. As you have it now it would be the last value N[8 because thats the last assigment made.

The error in greater detail:

  1. i=0: T=0 and the result N[8 is a scalar value. You assign T[0<--N[8 and so T is a 1x1 matrix now
  2. i=1: T=[1x1] and the result N[8 is also a 1x1 matrix. You assign T[1<--N[8 and so T is now a nested vector with two elements - the first is a scalar but the second is the 1x1 matrix.
  3. i=2: T=[scalar; [1x1]] this mixed data structure makes your solve block fail.

While looking at your sheet I found an irregularity which I think applies for a Prime bug. Maybe someone can look over it and report them to PTC support (I won't do so) if appropriate.

  • I played around with the first solve block and the constrained for theta.2 and wondered, why the value of theta.2 is that big when we do not constrain it (picture 1).
  • I wanted to add a similar constraint for theta.3 and first just copied the first constraint which i had now twice. You would expect that this does not change anything, but far wrong - the value of theta.3 changes!!! (pictures 2)
  • I then changed the the second constrain to apply for theta.3, but now the solve block failed. I allowed theta.3 to be in the range from 0 to 2*pi (there sure has to be a solution in that range) but to no avail - that alone would apply as a bug, I think. Then I changed the range for theta.3 to -10^6 to +10^6 but Prime stills does not find a solution!! (picture 3). Even larger ranges may give a result for one or both of my evaluation.

1.png

2.png

3.png

Thanks Werner for the detailed expanation.I corrected it and it now works fine

Vishniu Gopalakrishnan wrote:

Thanks Werner for the detailed expanation.I corrected it and it now works fine

You are welcome! Glad it works for you now.

Top Tags