2690 Views 26 Replies Latest reply: Feb 25, 2012 4:27 PM by Maneki_Neko
28 posts since
Feb 7, 2012
Currently Being Moderated

## Closing a "Solve Block" around the constraint that a vector cross product be zero

Hello World.

I am using a solve block in MathCAD 15, and it does not close around a constraint that a cross product of two vectors have a root of zero.

In this solve block there is some matrix algebra and some that functions, such that a vector (R0) starting out at one orientation, after two bounces (in two mirrors rotating on two orthogonal axes), ends up in another defined location.  There are two mirror positions (alpha1 and alpha 2) which satisfy these conditions completely and uniquely as long as skewness of the initial vector is 'reasonable' for the physical arrangement (e.g. under 30 degrees).  The clocking may be anything. In this example it is set at 90, which drives alpha 1 to the exact value of 45 degrees.

In this set of equations, when the root of a cross product between the vector between the last two points of the vector chain (a point of reflection off the last mirror and the destination point) and the unit vector for the reflection off the second mirror, is solved such that root is zero, then both mirror angles are found.

In the first example (blue) the Solve Block does not close, and the cross product error is large.

The second example (red) I solved the equation by manual search (this is not hard, but is slow), by perturbing the values of alpha1 and alpha 2 until the cross product was acceptably zero.

Why can't the solve block do automatically, what I find it relatively straight forward to do by hand?

I suspect that there is some kind of protocol error, but I don't see it.    The whole file is attached, in compressed form.  The green colored solve block is on page 8, the red colored is page 9.

Thanks,

Robert

Attachments:
• 10,077 posts since
May 11, 2010

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.

• 10,077 posts since
May 11, 2010

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.

• 10,077 posts since
May 11, 2010
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.

• 10,077 posts since
May 11, 2010

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)

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

is fine.

• 10,077 posts since
May 11, 2010
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.

• 10,077 posts since
May 11, 2010

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.

• 10,077 posts since
May 11, 2010

• 10,077 posts since
May 11, 2010

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.

Attachments:
• 10,077 posts since
May 11, 2010

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.

Attachments:
• 10,077 posts since
May 11, 2010

Plainly this is not what the solve block does.

You are right. It doesn't

#### More Like This

• Retrieving data ...