Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Hi to everyone!
I'm a newbie here and need help finding the idea for the solution to my issue—a brief explanation of the problem.
Mathcad Prime 9.0.0 is used for the modelling.
There is a FOR loop for which data is calculated, and there are conditions for selecting the coefficient. If the condition is TRUE, I want the program to choose the k1 and f values to be represented in the augmented matrix in the output.
But, as I can guess, the problem that prevents my loop from performing as it should in the type of input variable - each i-th value of the input variable u-value has to be checked for a condition—if it is TRUE, it goes to the list of output values; if FALSE, it returns an empty matrix.
Mathcad doesn't seem to recognise the particular u-value; it simultaneously recognises all the set of u-values [matrix]. Thus, I probably have the error message "this value must be a scalar."
PS The attached file could clarify my issue.
I would appreciate any information and help you can give.
Solved! Go to Solution.
I am not sure if the attached modification does what you intended, but I am pretty sure that you don't need to create any vectors (vector index i) in your program.
See if the result of the attached file meets your expectations.
Zs1 and Zs2 are 2x2 matrices defined in front of the program
The problem is that d1 and d2 are vectors within the loop. At each iteration, their next value is the whole of the current value ... which is a vector. Consequently, Interval creates a deeply nested vector of vectors and, hence, the "must be a scalar" error.
You could try initializing d1 and d2 to be single-element vectors and then using d1i-1 and d2i-1 within the loop; as i runs from 1..n, and your ORIGIN=0, this should pick up the first values of d1 and d2, and give you the desired results.
However, you have further problems further down the program in the expression Zs2*Zi*Zs1 as neither Zs2 nor Zs1 seem to be defined.
Stuart
@StuartBruff Thank you for such a simple explanation.
It is a way to see that my idea with these vectors is probably not the best way to iterate variables...
I'll try to think of what could be replaced instead.
I am not sure if the attached modification does what you intended, but I am pretty sure that you don't need to create any vectors (vector index i) in your program.
See if the result of the attached file meets your expectations.
Zs1 and Zs2 are 2x2 matrices defined in front of the program
It looks pretty cool and meets my requirements. But, to be frank, I would like to sort solutions which meet my restrictions and not see all the dozens of "0" values in the final INTERNAL matrix.
Nice to understand that here, in the community, I found the solution for my last month's headache.)))
@Ivan_Pat wrote:
It looks pretty cool and meets my requirements. But, to be frank, I would like to sort solutions which meet my restrictions and not see all the dozens of "0" values in the final INTERNAL matrix.
What do you mean by not see the zero values in Internal?
Werner's version of your program returns a lot of zeros because that's what the conditionals select. I've modified Werner's program to return u_value, d1, d2, and d1+d2 in addition to f and k1 to allow inspection of the values.
Do you want the program to return Internal with the zeros and then remove them, or do you want it not to add the zero f and k values?
One external method is to apply a filter function to Internal that selects for f and k1 both being non-zero. There do not appear to be many non-zero values. Is that what you would expect?
Stuart
I have Mathcad Prime 10 so can't save my worksheet as Mathcad Prime 9. I recommend that you upgrade to Mathcad Prime 10, if possible. You can install it in parallel with Mathcad Prime 10.
@Ivan_Pat wrote:
It looks pretty cool and meets my requirements. But, to be frank, I would like to sort solutions which meet my restrictions and not see all the dozens of "0" values in the final INTERNAL matrix.
Nice to understand that here, in the community, I found the solution for my last month's headache.)))
The zeros clearly stem from the else branches in the two if-statements.
The condition seems to be not fulfilled for most values.
I just noticed now that the condition in both if-statements is basically the very same, so this part of the program could be simplified.
As the start values for d1 and d2 are 0.1 cm and 0.5 cm and then are multiplied by positive numbers (i), they never can be zero or negative.
We can therefore omit asking if they are larger than or unequal to zero - they sure are.
I added a header line and added the index i as well as the values of d1 d2 and u_value (for space reasons with units stripped) for your information similar to what Stuart had done. Return values are created only if the conditions are met, so you get rid of the double zeros in the result matrix.
This creates a matrix with just 13 data rows.
I also added a routine Internal.all at the end of the sheet to create all 100 data rows so you can inspect the corresponding d1 and d2 values.
Unfortunately scrolling in a large matrix is horrible implemented in Prime 😞
But its easy to explain why the output of valid values is just a small matrix:
Our program starts with d1=0,1 cm and d2=0.5 cm and creates 100 pairs of d1-d2 values by increasing d1 for 0.1 cm and d2 for 2.5 cm in each step. The last pair of values thus is d1=0.1 m and d2=2,5 m.
For the first 10 pairs the condition u_value<0.25... is not met.
And for the pairs #24 up to #100 the condition d1+d1<0,6 m is not met because d2 is already too large.
I am not sure if you really wanted to increase d1 and d2 simultaneously the same time or if you rather wanted to increase them independent from each other, thus creating 100 * 100 = 10 000 pairs of values!? This would require two nested for loops.
@Werner_E You are right " As the start values for d1 and d2 are 0.1 cm and 0.5 cm and then are multiplied by positive numbers (i), they never can be zero or negative." These values apriori will be positive non-zeros. We can omit such conditions.
Excellent, that is what I wanted to get.
Thanks a lot. Problem solved.
@Werner_E wrote:
Zs1 and Zs2 are 2x2 matrices defined in front of the program
I'm not sure whether it's my eyes or brain that needs checking ... no, scrub that; I've just had my eyes checked. 🙂
I'd modified d1 and d2, and Mathcad threw up a "this variable is undefined" error on Zs1 or Zs2. I might have accidentally modified a variable's name when editing the program.
Stuart
@StuartBruff wrote:
@Werner_E wrote:
Zs1 and Zs2 are 2x2 matrices defined in front of the program
I'm not sure whether it's my eyes or brain that needs checking ... no, scrub that; I've just had my eyes checked. 🙂
Hmm, given from what you wrote about you 4K notebook display and the zoom/scaling factors you use, it seems not to be your eyes.
And judging from the quality of your contributions it can't be your brain, either.
Maybe its just a matter of "Nobody's perfect" 😉