I am trying to solve this equation without success so far
am I missing something here or the equation simply does not have a solution?
mathcad prime 9.0.0.0
thanks!
Solved! Go to Solution.
"idx2val" is a function I wrote.
The "match" function returns a vector consisting of 1 or more 2x1 vectors which contain row and column of the position the value was found. "idx2val" uses such a 2x1 vector as input and returns the corresponding alpha and phi value.
The function definition is to the right of the right margin so you may have to switch from "page view" to "draft view" to see it.
The function definition could also be seen in the screenshot I posted here: Link to reply
EDIT: The zero after "Match" is not a function argument so it does not appear in the argument list. Simply type an opening square bracket after the closing parenthesis in "match(....)" which is the keyboard shortcut for a vector/matrix index
You will have to define BB as a function of alpha to be able to take the derivative with respect to alpha.
I can't check if Prime will be able to give you a symbolic solution for the zero(s) of the derivative (phi, L, p and Mu are undefined) because I am limited to Prime express which does not allow for symbolic operations.
Usually the symbolics ignores the assume modifier or even chokes on it.
Do you really need a symbolic solution?
If you can provide values for the undefined variables you may use the numeric "root" function or a solve block with "find" to get a numeric solution.
BTW, the symbolics does not know anything about units and so it also does not know about the pseudo-unit 'deg'.
But you can tell the symbolics what 'deg' means by writing
somewhere at the top of the sheet maybe on the right hand not printable side or in a collapsed area. 'deg' should be labelled as "Unit" for consistency.
Did you realize that in your assume-modifier you used 'psi" but 'psi' does not appear at all in the function definition of BB. Probably you meant 'phi'. But as already written I doubt that the symbolics will respect that assume-modifier at all.
'phi' appears cos(phi) but also outside a trig function at the end - is this as it should be? But I guess its value does not matter anyway if you solve for alpha. But then, I doubt that Prime will be able to find a symbolic solution anyway.
EDIT: I have to correct what I had written. It its not mandatory to define BB as a function of alpha (although it would certainly be good style to do so). It would work OK the way you did as well. So if Prime comes up with "no solution found", it could either mean that no solution exists or that Primes symbolics is not capable enough to find it. In your case, I suspect that the derivative actually has no zeros.
Thank you, still a lot of useful information here
maybe, what if I was to rephrase the problem and instead of finding the zeros (which, from the figure that the other reply posted, doesnt seem to exist if I am looking at it correctly) instead I wanted to find the value of alpha and psi that results in the lowest value of BB? that is what i am trying to achieve here. I dont need to do it symbolically btw. Any input is appreciated.
thank you for sharing this..what I am trying to achieve is to find the value of alpha and psi that results in the lowest value of BB
I dont need to do it symbolically btw. If you have any advice that would be great.
So your function BB should be a function dependent on TWO arguments, alpha and phi? Is this correct?
Then a partial derivative wrt alpha would not have given you the desired extremum.
You would have to solve the system you get when you set zero both partial derivatives (wrt alpha AND wrt phi).
If you don't need a symbolic solution you sure can try to numerically solve the above mentioned system.
But you would have to provide numeric values for L, M.u and p !
Guess they should not all equal to 1 as ttokoro had chosen in the absence of a specification from you.
Once you provide numeric values, a solve block with "find" should be able to find a solution.
Another way would be kind of brute force. Create a matrix using a more or less dense net of alpha and phi values and use the "min" function to fund the minimum of all values. To get the indices of the corresponding alpha and phi values you could use the "match" function.
But again - this is a numeric approach and you would need to provide numeric values for the three unknowns.
A further option is to use the "minimize" function on function BB. You may use it in a solve block so you can add the additional restrictions for alpha and phi. Of course you still need values for L, p and M.u.
An additional problem is that your function BB may also return non-real values and you have to decide what to do with them.
If you want them to be ignored by 'minimize' and 'min' you may define and use a function which sets non-real values to a very high value, like
To avoid having to evaluate BB2 twice you may use a local variable to store it.
Here in MC15
Just gave the approach using "minimize" a try in MC15.
As you can see you don't get the absolute minimum that way but rather loacal minima which depends on the guess values provides.
Some guesses fail because the function would return a non-real result using these values
And here is the approach with the minimum of the matrix of values. I replaced non-real values by 10^3 which effectively lets them be ignored.
You may notice that the minimum found also depends on the mesh size you choose (nalpha and nphi). Changing it just by +/- 1 may slightly skip over the best value. So you have to try it with several values and keep the best.
The best I could come up with (but I used dummy values 1,2,3 for L, m.u and p) was -92.233 with phi right at the end at 85° and alpha=0.66.
If the minimum is actually at the end of the range for alpha (85°), then in all probability there will not be a horizontal tangential plane there and then setting the gradient to zero cannot provide the result.
But of course the situation can look completely different with different values for the three unknowns.
I attach the MC15 file. You should be able to convert it to Prime9 format and play around with it.
Thank you for the detailed answer.
Indeed, I have values for L, p and Mu, they are:
L = 5.6 m
p = 10.73 kPa
Mu = 158.9 kN
(these values might change but they shall not be far away from that range, say +/-20%), BB will be given in kN
1. first follow up question I have is: how do I convert the .xmcdz file to .mcdx? so i can open the file you provided on mathcad prime?
2. I was able to use the minimize function as you wrote it and obtain the correct results (I have the results to check them)
3. I am wondering how to combine the function B2 and pass it to the minimize function so that it always ignores non-real numbers (although it already seems to do depending on the initial guesses, as you showed
4. the approach using the matrix of values seems to be the most 'complete' (as minimize may result in a local minimum as you stated, and this approach seems to incorporate the B2). In trying to write this solution I ended up with the following error:
Using the values with the correct units showed me that I had typed the formula wrong in MC15 - the square root extended to far 😉
ad 1) When you installed Prime 9 you were given the option to check the box to install the legacy files converter. If you didn't you can run the installer again and add the converter. When the converter is installed you should be able to use it from the Input/Output tab. Its greyed out in the picture because I am limited to the free Express version which does not allow to use the converter:
A .xmcdz file is just a compressed (zipped, hence the "z") .xmcd file. I guess that the converter should not have problems using it, but I can't check so. If it chokes on the file, I sure can repost it in non-zipped format. But it looks like you already retyped most of the vital part anyway.
ad 2 & 3
To use B2 you simply replace BB by B2 😉
But when I do so in MC15, things go havoc and the values for alpha and phi suddenly are outside the desired range.
No wonder, we did not tell Mathcad that it should respect these ranges. To do so we have to use Minimize in a solve block. A solve block looks differently in Mathcad and in Prime. In Mathcad its simply started by the keyword "Given" and ends when you use a function like "find", "minerr" or "Minimize". All in between is part of the solve block and you can add additional constraints. In Prime the same functionality is achieved by inserting a solve block from the Math ribbon via "Solve Block".
I was surprised to see that a minimum was found at the lower end of the phi-range even though the guess was fairly large with 75°.
ad 4)
This method seems to give reasonable results but chances are that you miss a minimum with a "wrong" grid size.
As an example a grid size of 1500 for both values yields a minimum of -150.43 kN, but increasing the grid size to 2000 for each in the hope that a denser grid would give a more precise, even lower result, just gives us -144.49 kN.
Interesting, that phi is now at the higher end of its range near 85°.
But once such a value is found it might be of value to zoom in. Here we just look for alpha between 0.1 and 0.15 and phi between 83° and 85°.
Here again we get different, sometimes higher, results when we change the grid size, but usually all results are below -150 kN.
According the error you get: You have to use 10^8 N (or just 1 kN as I did in MC15) in the "if" function and not just the dimensionless 10^8. The "min" function can't work with matrices with mixed units. Whats smaller, 2 N or 5 V ? 😉
Modified MC15 in xmcd format attached
Thanks again!
so looking at the results, it looks like the last method (the grid one) seems to yield better results (despite the issue of being dependent on the mesh size)
I just downloaded that attached file and converted it to mcdx. however some functions doesn't seem to work after the conversion
therefore, I am just trying to find the function idx2val, I can't seem to find it in the function list and typing it doesn't seem like mathcad recognizes it
(in fact, a side question, it looks like mathcad doesn't always automatically converts a function when you simply type it, I am seeing myself always having to find the function in the list and clicking on it, is there a way to change this?)
something else I am trying to understand is, what is that Zero after the Match function?
what is that Zero after the Match function?
It's an index, to get the first found result (even if it is the only one).
The function Match() returns a vector (if it doesn't return an error), and 0 is the index of the first element of that vector (by default, unless you set ORIGIN to another value). The safer option is to replace 0 with ORIGIN (full capitals), to make the expression independent of the actual value of ORIGIN.
Success!
Luc
thank you
also, why can't I seem to find the function idx2val on mathcad?
the zero after the match function is not separate by a comma or anything, but when I prompt Match on my mathcad, is opens with arguments.
also, why and is it possible to fix the functions that are not working after i converted the file to mcdx?
if I can understand these, I can close this topic
sorry some questions are pretty basic, I am a new user to mathcad
Which functions do not work after conversion?
You may post the converted sheet for inspection.
This is what i obtained after the conversion
scroll to the end of the file
by 'not work' I mean that BBmin is returning "?" as well as phi min
oddly alpha min is being calculated.
"idx2val" is a function I wrote.
The "match" function returns a vector consisting of 1 or more 2x1 vectors which contain row and column of the position the value was found. "idx2val" uses such a 2x1 vector as input and returns the corresponding alpha and phi value.
The function definition is to the right of the right margin so you may have to switch from "page view" to "draft view" to see it.
The function definition could also be seen in the screenshot I posted here: Link to reply
EDIT: The zero after "Match" is not a function argument so it does not appear in the argument list. Simply type an opening square bracket after the closing parenthesis in "match(....)" which is the keyboard shortcut for a vector/matrix index
I still cannot get the idx2val to work, sorry
I setup the idx2val as a function (see highlighted), same for the definition of idx2val itself
and yet I get this:
Actually a function which you write yourself usually is not labelled as "Function" but rather as "Variable". But it looks the the function definition as well as the function call are labelled as "Function" so it should work OK.
But from the picture it looks like the function definition is dimmed out, meaning the region is for some reason deactivated. Look if this is the case and uncheck "Disable Region" (Calculation ribbon) for this region, so the function definition is active again.
I just checked and the button "Disable Region' is not selected when I click on either region.
I found the "Disable region" under the 'Calculation' tab
I attached the mathcad file here
Now the definition of "idx2val" is in a different position than in the picture you showed before.
The definition is now in front of the definition of alpha.i, etc. and so the definition fails! You should see the error message about alpha.i not being defined.
Move the definition down below the definition of alpha.f, etc. and it should work.
Your file is hard to edit because you seem to put all your calculations inside a text area - why??? Its annoying not being able to move math regions around freely.
So as you can't simply move the function definition of idx2val (which is outside that text region) down, you have to use cut and paste.
So I suspect that the converted sheet worked OK right after conversion but started to fail when you started to edit it 😉
You could put the matrix creation and the calculation of alpha and phi in one program to get rid of the function "idx2val" altogether and keep all in one place. simply chose the dataset (2x3 matrix) to use and off we go
You can omit the division of Bmin by N in the program and the addition of N to BB.min in Prime becaus eon contrary to Mathcad Prime allows mixed units in matrices.
thank you very much for proposing an alternative solution
however, in trying to write this one I have other questions unfortunately...
what is M? (previously it was the result of the loop)
and what is N? ( I understand it can be omitted, but what is it?)
where were they defined?
EDIT: OK, I replaced 'M' by 'Result' and I removed N, and now it works!
thank you 🙂
@CN_13593194 wrote:
thank you very much for proposing an alternative solution
however, in trying to write this one I have other questions unfortunately...
what is M? (previously it was the result of the loop)
and what is N? ( I understand it can be omitted, but what is it?)
where were they defined?
EDIT: OK, I replaced 'M' by 'Result' and I removed N, and now it works!
thank you 🙂
Yes, my bad, Glad you found it yourself.
M was a left over from the other version . In the program I had chosen 'Result' for the name of the created matrix and forgot to change the parameter name in the match function.
N is simply the unit Newton.
Mathcad (15) does not allow for mixed units in a matrix. The program returns three values in a 1x3 matrix, the minimum value of BB, alpha and phi. alpha and phi are dimensionless scalars and to be able to put Bmin in the very same return vector, it was necessary to make it dimensionless, too, as actually Bmin is force. So I divide Bmin by Newton (any other force unit would do equally well) and later I add the unit Newton again to that variable. Using a matrix is the only way for a program to return more than one value, so this inelegant trick was necessary. Its not necessary to do so in Prime because Prime happily accepts a vector consisting of a force value and dimensionless scalars. Prime does not have many advantages over Mathcad (its rather the other way round) but being able to use different dimensions in one matrix sure is an improvement.
that is not what happened. but to be 100% sure I downloaded the file again, converted it, and did not touch a thing (see attached)
please see how it still has a bunch of "?" all over it
the reason why I do all my calcs in a text box is because I want everything to be aligned
I personally dont like boxes that are floating around, and I have to be aligning one by one
I see that Prime has made a bad job doing the conversion.
The evaluations of alphmin, etc. are placed above(!) the corresponding region with "Minimize".
They should be moved so the are in the same line.
I did so in the attached file - it still shows an error simply because "minimize" is a Prime feature not available in the Express version.
The first two Minimize regions should work after you let the sheet recalculate.
If they still fail, it might be because of Prime not choosing the correct label for the variables. All should be labeled as "Variable" or as "-" meaning automatically.
But the function idx2val is not deactivated and also at a correct position. It definitely should work - at least after letting the sheet recalculate (Ctrl+F5).
I tested it but as programming is a premium feature the creation of Matrix M did not work for me.
So I deactivated the matrix creation and created the matrix M using range variables. As you will see in the sheet it was also necessary to define an "Im" function because the built-in is considered 'premium'.
After the function M was created, the rest of the sheet seems to work as it should!?
You may delete my new matrix creation an activate the original one - guess it will work OK as well.
Modified Prime 9 file attached.
does this mean I would have to define this (below) twice?
@CN_13593194 wrote:
does this mean I would have to define this (below) twice?
No, but because idx2val was written as a quick hack it depends on the six variable values and so these values must be defined in front of the definition of that function. So the definition at the top should suffice.
In fact you actually should not define it twice because in case the second definition is different from the first, the calculation of the matrix M uses the second definition, but the function idx2val uses the first one which very likely would give wrong results.
It would have been a better style to make the 2x3 matrix a second argument of the function.
That was also one reason why I posted the allinone calculation (the one with the wrong 'M' instead of 'Result').
Finally here is a generic function for finding the minimum of a function in two variables by brute force.
Arguments are:
1) the function in question (should be unit-less in arguments and result)
2) a 2x1 vector with the low and high bounds of the first function argument ("x")
3) a 2x1 vector with the low and high bounds of the second function argument ("y")
4) either a 2x1 vector with the grid line numbers in x- and y-direction or a single scalar which is then used for both directions
5) a number which determines how often the algorithm should run. With each run only the small space around the minumum found in the previous run is considered, so this number indicates how far we zoom in. If the number is 1 the result is similar to what we had achieved so far by creating a matrix and using the min function.
To save memory the program does not create huge matrices and uses min on them but rather cycles through the grid, calculates the function value and keeps the smallest so far.
Examples show that its still important to use a larger number for the grid size because if the first grid misses the local min, further zooming in will not bring it back again. Its also quite sensible with respect to the grid number. 499 might give a good result while 500 may return a value not that good.
So experimenting and trial and error still applies.
Here is the function
And here some usage examples
MC15 sheet attached, the function is on the last page