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
I want to write a function for how the weight changes along depth. I have attached a worksheet (prime 7) which describes what I want to achieve.
Thanks for all support!
Solved! Go to Solution.
@StuartBruff wrote:
Can I play too? 😃
Sure, you are welcome 😄
After all, there are so many ways to skin this cat...
I have P5 and P6 still installed, but they will only run in Express mode as the new license file is not valid for versions below P7 (and also not for Mathcad). I never had installed P7 and P8 as I considered the new symbolic too weak and could not spot significant improvements from the descriptions of P7 and P8.
I no longer know what prompted me to try P9 again after all. P10 gave the impression of greater improvements. Here in the forum it has been shown that the price for this was probably some newly introduced P10 bugs. Sure, more feature improvements in the same time with the same amount of programmers definitely means less time for testing.
Possibly something like this?
Or, if you want to change the profile from linear,
There are many other ways of skinning this particular cat. This was simply the first one that occurred to me. Hopefully, others will be along to present better methods ... some so obvious in retrospect that I will spend a good few fruitful hours kicking myself!
Stuart
I've no idea why I left those "d"s in the functions. I meant to delete them.
Here's the d-deleted form for the functions.
And a couple of functions that helped me check the results of the weight functions.
Stuart
I made an attempt myself, but failed. I want it in a more simpler manner.
What is wrong whit this code?
z include z[1, z[2, z[3. Therefore, you shoud use different valiable name such as z1, z2, z3.
If you want use z[1, z[2, z[3 for only one variable z with many rows, compared value name must change such as x to compare each z rows. So I made Ans(x) function not Ans(z).
A couple of things are wrong with it.
First, your argument name, z, is the same as your layer thickness vector name, so Mathcad doesn't know what you want. I've changed the argument name to d.
Second, you are testing against the layer thicknesses, not against the depths spanned by each layer. That's where a function such as cumsum comes in handy to give you the depths at which each layer starts ... assuming they are contiguous.
Stuart
As far as I can tell from your screenshot you are using vector indices for z in your program. That way you can't use z as formal argument as Stuart already explained.
You actually CAN use z as formal argument if you use the z-values with the literal indices otherwise.
It wold be consequent to avoid using the other vector as well and use the variables with the literal indices instead.
Further you assigned some values to a variable w inside of your program. Note that this does in no way correspond to the function w. You could use any variable inside your program, it has not to be the function name. The function value returned is determined either by an explicit 'return' statement or by the value of the last expression evaluated. The latter is the reason why the program shown below works without using a local variable w and without any 'return'. And no, its sure not good programming style!
The example below tries to follow your attempt as close a possible but it has a few flaws. One of them is that it does not define a return value in case the argument z is outside the range of 0m to 12 m. It relies on Prime automatically assign some values (which is decreasing any further for values lower than 0m and is undefined (throws an error) for values larger than 12m. Its sure better programing style to define values your own (it may be a NaN if you like) rather than omitting them.
The main flaw IMHO of this approach is that its not very flexible. Its just some work you will have to do if you add or remove a layer.
That said I strongly would suggest that you stay with Stuarts solution as you would not have to change anything in his function 'weight" once you add a layer and its characteristics.
Anyway, here is your attempt modified to give the desired result - study it and you will see where you failed. And then give Stuarts solution a second look as it is clearly preferable 😉
I guess that the index "4" instead of "3" in "k.4.inc" is a typo, but I left it as it was
I don't have Prime 7 installed. so that the attached file is in P9 format and you have to stick with the picture posted.
EDIT: There was an error in this approach which is now corrected (highlighted in yellow in the screenshot above)
I couldn't resist 😉
Here is another version of a weight function which uses the vectors you defined and should work the same if you add or remove layers.
The repeated use of the (partial) sums is of course inefficient and probably also more difficult to read compared to the one-time use of Stuart's ‘cumsum()’
Prime 9 file attached
EDIT: Using Stuarts 'cumsum' it may look like this
Can I play too? 😃
I've got Mathcad Prime (MP) 10 and I've dug out an old laptop with MP 7 and MP 8 on it (both Express versions), but no MP 9, I'm afraid.
Stuart
@StuartBruff wrote:
Can I play too? 😃
Sure, you are welcome 😄
After all, there are so many ways to skin this cat...
I have P5 and P6 still installed, but they will only run in Express mode as the new license file is not valid for versions below P7 (and also not for Mathcad). I never had installed P7 and P8 as I considered the new symbolic too weak and could not spot significant improvements from the descriptions of P7 and P8.
I no longer know what prompted me to try P9 again after all. P10 gave the impression of greater improvements. Here in the forum it has been shown that the price for this was probably some newly introduced P10 bugs. Sure, more feature improvements in the same time with the same amount of programmers definitely means less time for testing.