Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
Hi, In the attached sheet Minimize is not working correctly. The Minimize value given changes to the Guess value all the time giving an incorrect result. Further in the sheet I am using Find to solve a matrix equation and then using this result in a subsequent calculation (Transfer Matrix method). The first Find calculation seems to work but the second identical calc throws an undefined variable error, cannot see why. Any assistance would be appreciated. thanks Ross
Your first solve block has a function of omega. Your second solve block has no function, so Mathcad has no variable that it can change. The error message is misleading. Since version 12, this is the only error message a solve block spits out, regardless of what the problem actually is. This serious bug has been around for at least a decade, but neither Mathsoft nor PTC could be (or in the case of PTC, can be) bothered to fix it. A solve block has to have a function of a variable, or variables, that the solve block can change to find a solution.
Richard, Thanks for taking the time to assist. Minimize seems to do some strange things! Please take a look at the attached sheet which is an earlier version of the one posted. Two things are happening I do not understand. 1) In this sheet Minimize works correctly for both mimima one at 536 rad/sec and the other at 929 rad/sec with the higher value being evaluated with the constraint w>700 - all good. For the 929 value a simple division by 2.pi reverts back to the earlier 536 solution above. Why is this so. I thought things reset after the second 'Given" statement with new guess values and constraints.
2) Why doesn't the graph of det(BB(w)) not show in the in the plot below the first "Given" statement? It shows fine in the copy to the RHS but as soon as you drag this graph down half a centimeter the graph disappears?
So Minimize seems to evaluate the minima within the assigned constraints correctly in the sheet attached to this post but does not in the earlier sheet.
In your response below to the first sheet I attached in the original post you say there is no function in the second solve block, but I am using the same function in the second "Given" as was used in the first but merely seeking to find a second minima of the same function. This is the same solve detail as in the sheet attached to this post but Minimize does not work for either solves in the fist sheet it simply gives the Guess value.
Cheers
Ross
ad 1)
Minimize can be used in a solve bock or standalone.
The only reason for using a solve block in your sheet is the constraint omega>700 (you could define CC before the "Given".
When you call minimize the second time you call it standalone and so the constraint omega>700 is not considered. Thats the reason you get the value 536 again.
ad 2)
Mathcad reads the sheet from top down and from left to right. Every region has its own reference point witrh that respect (you can see it when you chose View-Regions).
The plot on the right is above the definition omega:=330 and so omega is still the range you have assigned above and this range is used for plotting.
If you drag the plot region down a bit so that its below the redefinition of omega, omega is a single constant value, not a range anymore. So only one tiny red dot would be shown at omega=330 (you will have to set the left value on the abscissa to something like 300 and change the Line Weight of the plot to a higher value to see that dot).
Workaround would be to use a different name for the variable in the plot. A tricky name would be "omega.". Thats the dot you would use for a literal index without anything after it. You will see the dot while the focus is on the plot region, but when you go out it will look like a normal omega.
Werner,
I owe you a beer! I understand item 2 and that makes perfect sense. On the minimize function I am still having trouble understanding how it works. I understand your comment regarding the fact that for the second use of Minimize it disregards the earlier constraint. However, I cannot seem to get Minimize to give the correct answer with or without a Given. See attached. It always seems to give the guess value. Can you advise what I am doing wrong. I would like to determine the first 5 - 6 minima in the attached graph of det(BB(w)). The online Help menu gives a method to find additional minima where you zero out the first minima. I could try this but need to be confident that the first minimum is correct.
Thanks Ross
The answer of minimize will be the same with or without Given unless you write your constraint omega>700 between Given and Find.
The reason you don't get a solution probably is that your function BB throws an error when the values of omega are near the expected minimum. Try BB(345) or BB(345.5). Obviously Minimize can't play around with the value of omega without getting an error and so it settles with the guess value (just a guess).
OK, some further look showed that the problem with your solve block is, that your function BB will only evaluate for even integer values of the argument omega and fail for any other.
To find a solution Minimize will change the value of omega ever so slightly (and sure not in steps of 2) and look in which direction the function value will get smaller (the algorithms used actually are not that simple). As BB and |BB| will always throw an error, it settles with the guess.
So the first step necessary is to create a continuous function to use for minimize. I did this by using linear interpolation if the argument is not even.
It showed that this worked, but is not enough as we always would get the very same minimum at 346, regardless of the guess value. Thats OK, as it seems to be the absolute minimum anyway. So I added a constrained telling the algorithm that the value of omega always should be greater than the guess. This means that you have to chose your guesses carefully. The guess and the value the searched for value should be greater than have to be two different arguments of the solve block function and all arguments of this function must be also arguments of the function we wish to minimize (even though its not used there. This is the reason for detBB and det BB2 and min_omega and min2_omega.
Looks like it works now as you intended.
And here is a less tricky. more straightforward approach.
As your function |BB()| will evaluate only at the 1000 different equal values of omega, it would be more appropriate to use vectors and the function localmin from the Data Analysis Extension Pack:
Werner,
Looks like I owe you two beers!! The solution to Vectorize BB and use Localmin is very elegant and so efficient. How on earth programmers develop the code to process the math is amazing.
I have incorporated your solution and as always seems to be the case with non-expert users of Mathcad there is another issue further into my problem! If I could burden you further... the attached sheet seeks to use a Transfer Matrix method for a target frequency (omega = 324 rad/sec, in this case one of the natural frequencies from LocalMin) to substitute values from one Station into the next Station using a Given/Find solve block. My matrices are of the correct dimension but the second solve block throws and error I am unable to fathom. My calculation is clumsy and lengthy but hopefully shows the intent of serial substitution.
If you can assist that would be appreciated.
Regards,
Ross
Your sheet is quite a mess with all those regions overlapping and and arranged in criss-cross manner.
What I found nonetheless looking at the first failing solve block is:
1) There is a second region with "Given" hidden underneath one of the other regions. Thats the reason for the error message.
2) The solve block will still fail and this time using "Trace Error" tells us that Mathcad was not able to find a solution within the given tolerances. Set CTOL to a higher value like 10^-4 and you get a solution.
Werner,
Apologies for my poor housekeeping. You are right about the hidden Given and I had copied/pasted this problem to generate subsequent transfer matrix stations. I have gone through an tidied up all of the station evaluations. I get three Given solve blocks into the serial calculation and an error appears. The error trace indicates to change the CTOL. I have done this to the maximum allowable and the error remains. I have increased the damping of the bearings in this calculation on the basis that this might reduce the dynamic range of the calculation but this does not eliminate the error. Can you suggest anything else that might rectify the problem. If I cannot get past here the whole calculation is torpedoed which would be surprising given this Transfer Matrix method seems to be used in the literature quite regularly.
Thanks
ross.
I see that you already set CTOL to (usually unacceptable) value 1. You can set even higher values if you do it in the sheet itself. Simply type CTOL:=10 at the top of the sheet or you a global assignment anywhere in the sheet. But it may be that larger values than 1 are ignored anyway (at least values that large would not be useful anyway).
I guess that your solve block failing would mean that there simply is no exact solution to your equation.
In that case you could use "MinErr" instead of "Find" at the end of the solve block. This will minimize the sum of quadratic errors. There is a system variable ERR which you can evaluate after the solve block indicating the quality of the solution. You can set CTOL back to the default 10^-3 or another appropriate value.
When looking for R1 you get the same solution as with find with ERR approx. 10^-7. But when looking for R3 and R4 you get ERR in the range of 10^5 and you have to decide if those values still are valid and acceptable for your application.
Another option for linear systems is to use "lsolve". Note that the order of the variables in the result is different from the order you demanded in the solve blocks and you will have to change some signs.
E.g. the first value is -wc (you have to change the sign), the third value is Myc:
Werner,
Many thanks for those suggestions. I will try some of these options and see if I can get some sensible results. Your knowledge and perseverance are much appreciated. Cheers Ross
Hi,
I fear that something is wrong with the size of the matrices.
@-MFra- wrote: something is wrong with the size of the matrices.
Yeah. I should have noticed that. It was getting late though
MF, Richard, That's a touch embarrassing. In fact whilst I was noodling over the problem just before your responses I discovered the fact that the matrices are of different size. I have corrected that but I am still having problems. I will spend a little more time trying to rectify before summoning further assistance.
Cheers
ross