Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
I have a Mathcad document along the lines of:
r:=10mm
---------
Many equations using r and other variables.
---------
stress = 50 MPa
Is there a way to find the value of r that gives the minimum stress without totally re-writing the document?
I know this can be done relatively easily for discrete values of r by using a vector but I'd ideally like to do the equivalent of an Excel goal seek.
Turn your calculations into functions dependent on r, so that at the end you have a function stress(r):=.....
Then use "minimize".
If you have stress as a function of r, then Minimize will do what you want.
Hi Dan
try this one. Some simple equations that spit out a minimized value.
Hope it helps
Raiko
Trouble is my worksheet is long and complex and is not written using functions but straight definitions e.g. B:=2r rather than B(r):=2r
It doesn't look like it is possible to do what I want without rewriting every equation as a function of r because Minimize only works with functions.
Might be easier to set up the same equations in Excel and use solver as there are a few input variables apart from r that I'd like to change.
Is there a way to do it along these lines:
Given
r:=10
stress:=r^2
5<r<20
stress<1
Minerr(stress,r)=(1 over 10)
The stress<1 line is an attempt to force it to find the minimum value of stress even though it has to be higher than 1 to satisfy the constraints.
Why does the above not give (5 over 25)?
Here's another attempt:
Given
r:=10
stress:=1000
stress=r^2 (boolean equals this time)
5<r<20
stress<1
Minerr(stress,r)=(1.962 over 1.71)
If I right click Minerr and change to one of the other non-linear methods it gives (8.16 over 3.5) which is a bit closer to the correct answer of (25 over 5)
Why does it give these answers?
Dan Rose wrote:
Here's another attempt:
Given
r:=10
stress:=1000
stress=r^2 (boolean equals this time)
5<r<20
stress<1
Minerr(stress,r)=(1.962 over 1.71)
If I right click Minerr and change to one of the other non-linear methods it gives (8.16 over 3.5) which is a bit closer to the correct answer of (25 over 5)
Why does it give these answers?
You have three constarints now and Mathcad tries to minimize the overal errors in all three. You may weight a constraint by multiplying it with a factor higher than 1. Using (1-stress)*1000>0 will multiply the error made in this constraint by thousend, so the answer will consider this constraint more than the others.
Results in numeric approximations may highly depend on the guess values used and also may change significantly if the algorithm used is changed. This seems to be what you experience.
Usually Levenberg-Marquardt is a good choice, but in case of your solve block Conjugate Gradients seem to be more appropriate. Try it, use stress<30 and you get the (5; 25) answer you expected.
Use stress<50 and you get a different, but still valid solution.
Dan Rose wrote:
Is there a way to do it along these lines:
Given
r:=10
stress:=r^2
5<r<20
stress<1
Minerr(stress,r)=(1 over 10)
The stress<1 line is an attempt to force it to find the minimum value of stress even though it has to be higher than 1 to satisfy the constraints.
Why does the above not give (5 over 25)?
Here 10 and 100 are initial values for r and stress. Mathcad's numerics now play with r and stress independently and tries to find a good fit for the two constraints 5<r<20 and stress<10. The initial value is good from the very start and is not changed at all and stress is decreased until the constraints is fulfilled. Mathcad does not distinguish between < and <= here - its a numerical approx anyway.
If you have a range for r (that it must stay inside), replace the single value r:=10 with a vector of values that covers the range. It may be necessary to "vectorize" a few of you equations, but the sheet should compute and result in a vector of stresses--one for each value of the radius vector. Plot stress vector against r vector, or develop a curve fit between the vectors, to find the minimum.