


Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
Maneki_Neko Feb 23, 2012 12:41 PM (in response to Maneki_Neko)For those of you using earlier versions, here is the file saved as an M13 version.
The solve block which won't work is on page 8. Everything else seems to run fine.
Robert



Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
A.Non Feb 23, 2012 3:31 PM (in response to Maneki_Neko)A couple of things.
First, aside from the constraint issue, I am not sure that the solve block is doing what you think it is. Numerical assignments inside solve blocks are NOT part of the solve block. They didn't even used to be allowed. So if you think that somehow during the solve the value of n1, for example, is being changed every time alpha1 is changed, and that is then carried through to the equation for Pr1, it's not. I personally wish they had never allowed this, because it just leads to confusion. Take all the assignments outside of the solve block (that usually means before it). The only things you should have inside the solve block are equalities and inequalities. Nothing else, even if Mathcad happens to permit it. Your evaluation of the cross product is also NOT part of the solve block. The answer you are getting is just based on the guess values, not on the values the solver finds. Evaluate it after the solve block, based on the variables returned by the solve block, alpha1 and alpha2.
Second, the constraints in minerr are treated differently to those in, for example, minimize. The errors in the constraints are minimized along with everything else. In other words, they are soft constraints, not hard constraints. If you want them to act as hard constraints then you need to weight them very heavily. Replace the constraint with (R2 x r2_unit)*10^16=0. That will force the cross product to be effectively zero. This also applies to your constraints for alpha1 and alpha2.

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
Maneki_Neko Feb 23, 2012 3:37 PM (in response to A.Non)Very interesting what you have to say about weighting the cross product. I have never seen that done, however I can see that it is quite powerful as a method.
I will try that immediately.

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
A.Non Feb 23, 2012 3:39 PM (in response to Maneki_Neko)I don't think you will like the answer you get
I believe that's because of the other issues with the solve block though, which also need to be fixed.

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
Maneki_Neko Feb 23, 2012 3:55 PM (in response to A.Non)Okay. I absolutely have been assuming that N1 would be updated sequentially, and that in turn would up date Pr1, which would update r1 and so on, just as it would in many programming languages. If it is not doing this, then what do people do to get around this limitation in a Solve Block I wonder? Do I have to put all of those functions in an "uberfunction", set that to zero, and solve that? I wonder if this would be a good approach.
Robert


Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
Maneki_Neko Feb 23, 2012 3:48 PM (in response to Maneki_Neko)Okay. Weighting the cross product R2 x r2_unit by a factor of 10^10 changes the result, but only in the direction of the right answer. The initial 'guess' values still predominate. This is the very first time that I have heard about 'weighting' an equation inside a solve block, and I like the idea A LOT.
Now about what a solve block does: you are absolutely right. I have no idea what it does, aside from get me right answers (which I check by other means) most of the time (which is why I check them). So I am going to have to read your paragraph above very carefully, and try a few examples.
More soon.
Robert

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
A.Non Feb 23, 2012 3:58 PM (in response to Maneki_Neko)Okay. Weighting the cross product R2 x r2_unit by a factor of 10^10 changes the result, but only in the direction of the right answer. The initial 'guess' values still predominate. This is the very first time that I have heard about 'weighting' an equation inside a solve block, and I like the idea A LOT.
This applies only to minerr.
Now about what a solve block does: you are absolutely right. I have no idea what it does, aside from get me right answers (which I check by other means) most of the time (which is why I check them). So I am going to have to read your paragraph above very carefully, and try a few examples.
Take all the assignments outside the solve block. If you think that will stop the solve block from doing what you want, then it wasn't doing what you want anyway
Create a set of functions that depend on the variables you wish to solve for: alpha1 and alpha2. So n1 is a function of alpha1. Pr1 is therefore also a function of alpha 1. etc. Your solve block should contain equalities and inequalities based on those functions and the variables alpha1 and alpha2.

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
Maneki_Neko Feb 23, 2012 4:09 PM (in response to A.Non)Okay. I have a bit of work to do here to rework all these functions, as you suggest.
I wonder if it is possible to use a function as the argument of a function. Probably not.
This really does give me a clear direction in which to take this. I was attempting to use a solve block the way you would close a search loop around a collection of assignments when programming. Plainly this is not what the solve block does.
Best,
R.

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
Maneki_Neko Feb 23, 2012 4:13 PM (in response to Maneki_Neko)Hmmm . . . it does seem to be possible to use a function as an argument of a function. Well this is very nice.

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
A.Non Feb 23, 2012 4:23 PM (in response to Maneki_Neko)Hmmm . . . it does seem to be possible to use a function as an argument of a function. Well this is very nice.
You can pass a function of a variable to a function.
xx(a):=sin(a)*cos(a)
answer:=xx(ln(A))
But you can't define a function that way
xx(ln(a)):=sin(a)
makes no sense, and is not allowed.
You can in fact pass any valid expression to a function
answer:=xx(ln(A)+cos(A)32)
is fine.

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
Maneki_Neko Feb 23, 2012 4:27 PM (in response to A.Non)Okay. I am getting some very long and strange looking functions, which are the combined products of many other functions using yet other functions as arguments, and MathCAD is allow this. This is a capability I hadn't explored. Interesting.

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
A.Non Feb 23, 2012 5:12 PM (in response to Maneki_Neko)I am getting some very long and strange looking functions, which are the combined products of many other functions using yet other functions as arguments
Please post an example. This doesn't sound right.


Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
A.Non Feb 23, 2012 5:27 PM (in response to Maneki_Neko)That's not the right way to do it. It might work, but it is unnecessarily complicated. By several orders of magnitude. Please post what you have.

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
Maneki_Neko Feb 24, 2012 11:47 AM (in response to A.Non)Good morning Richard,
The problem occurs as a consequence of nesting functions within functions. When you combine five functions into five more functions and combined them again into yet another equation, pretty soon you have a hundred terms or more, and this gets unweildly very quickly. You can see this in the second of thie MathCAD 15 file attached.
Cutting and pasting the expressions into one another so that ALL the inputs are in terms of alpha 1 and alpha 2, leads to a single expression which is eight A4 pages wide, and has lost all of ease of editing and checking which the individual functions once had.
So my question at this point is very different from where we started. The answer to the question posed is: Can you close a solve block around a vector cross product is a resolute "yes". For the benefit of the readers who follow I think that starting a new thread at this point is a good idea, so that the key words and title are all tied to the actual discussion.
I will start that thread with the title. Since reassignments are prohibited within a solve block, how can expressions be kept to a manageable size. You were VERY helpful on this thread and I hope that you may be available to comment on the new one.
Thanks,
Robert

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
A.Non Feb 24, 2012 11:56 AM (in response to Maneki_Neko)Please don't start a new thread. It's not necessary.

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
Maneki_Neko Feb 24, 2012 12:16 PM (in response to A.Non)Understood about your preference on starting a new thread. I am a newbie to this list serve, still learning the expectations of the community and the written and unwritten rules. After 8 thousand plus posts, you are clearly one of the most experienced participants.
You do understand the problem however, that when you nest functions with five or so terms (a convenient and good modular size to test and verify independently) and then nest these expanded function inside another few functions in various ways, and them put this in cross product equation, in order to have everything in the solve block be a single expression (no reassignments allowed in the solve block) that the resulting expression is HUGE. Just HUGE. At this point all the ease of use and transparency of documentation which is the main reason to use MathCAD is lost.
Kind regards,
Robert

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
A.Non Feb 24, 2012 12:43 PM (in response to Maneki_Neko)If this was going to turn into a big discussion on nesting of functions vs functions calling other functions, I would agree with starting a new thread.
The way you are doing it is not necessary though. In fact, as you point out. it's highly undesirable because it makes it impossible to read, edit or debug. A function can depend on another function though, so the nesting is not necessary. See the example stuff highlighted in green. That's just an example, so you have a lot more work to do. You need to create this dependence on alpha1 in a sequence of functions all the way through the worksheet. You take the final functions, expressed as equalities, and put them in the solve block. If you have two such functions you can use Find rather than minerr, because you are solving for two variables. Then the constraints are hard constraints and you don't need to worry about the weighting. If you have more than two such functions you will have to use minerr.

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
Maneki_Neko Feb 24, 2012 1:12 PM (in response to A.Non)This distinction between having one function 'nested' inside another as opposed to having a function 'call' another is an important one. You state this very clearly in your annotation. The latter configuration is MUCH more compact, and preserves the modularity which is so important to efficient verification of individual functions. I am looking forward to trying this out. Thanks again.
Robert

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
A.Non Feb 24, 2012 1:17 PM (in response to Maneki_Neko)Here. It's up to you to check it's actually calculating what you want ti to calculate! I did not spend the time to look through your worksheet in great detail. I just made the solve block work in what seems like a reasonable way.

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
Maneki_Neko Feb 24, 2012 2:28 PM (in response to A.Non)Hi Richard,
I think that we are probably on the same page here.
The solve block, and how to use it efficiently with a half dozen functions which rely on another half dozen functions, is really the important question in this whole thread. It is the core of how the problem emerged. I was using a reassignment of a function in another function, which although *allowed* in MathCAD simply does not work. To get around this I 'nested' the arguments of functions in functions, and plainly the *clean* or the elegant way to do this is to 'call' the functions in the minor premises. In retrospect what you write seems really clear.
The rest of the file I shared in this thread is a specific application which will vary in the future, and will certainly be different for other readers. I am away from my work station at the moment, so I don't have access to a machine with which to try out what you suggest. This being said, the logic of what you wrote seems transparent.
Kind regards,
Robert



Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
Maneki_Neko Feb 25, 2012 4:27 PM (in response to A.Non)Hi Richard,
The method of using functions to call functions is new to me. As you explain it leads to a very compact notation. The solve block is now two lines long. Moreover it is the right answer.
For anyone who might be reading this in the future, I append the final solution below. The modularity of the functions is saved, and the result is very clean.
Thanks again.
Robert











Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
A.Non Feb 23, 2012 4:24 PM (in response to Maneki_Neko)Plainly this is not what the solve block does.
You are right. It doesn't

Re: Closing a "Solve Block" around the constraint that a vector cross product be zero
Maneki_Neko Feb 24, 2012 11:49 AM (in response to A.Non)After nesting all those functions within functions, I have a single expression in term of alpha 1 and alpha 2 plus various constants. This single expression is now eight pages wide. However the 'find' function now does find an answer for alpha one and alpha two. It is not the right answer, but the solve block now does
return an answer rather than an error code. Perhaps I made an error in all that cutting and pasting.
I am tempted to put the whole thing in a programming box with a little search loop. I know that will work.
I am going to look at this again in the morning.
Thanks so much.
Robert





