Community Tip - You can change your system assigned username to something more personal in your community settings. X
I am having an issue getting a function to produce the results I expect. I am not sure if it is an issue with one of my conditions or the function syntax itself. When I check pieces of the function, I get the expected results, but not when it is all together. I have attached a worksheet with the function that is not working. Any help would be greatly appreciated.
Solved! Go to Solution.
Could it be that it should read "t-d[Q-c" instead of "d[Q-c"? So your function should be
If this is the case, then it could also be written as
Would the output be realistic?
Your function at the top is OK. Its the functions Fs(c) below which are wrong. They will only return the value for Q=1 and ignore Q=1.
BTW, no need to make f() and f'() functions of c. As you use them only once it would suffice to make them simple variables (simply omit the "(c)").
Thanks for the reply. I am trying to get the top F function to equal what I had below. Fs(10.5in) should equal (-116 120). Is there another constraint I need on the fs and f`s values?
I can see now where it is getting the values from, but I am still having trouble getting the function to yield the results I want.
As already written your functions below fully ignore index 0 in the vectors E.s, d and f.y. In other words, the calculations in Fs are made for all values in those vectors, but the return value is just that of the last index. So it would not make sense for those variables to be vectors at all.
If you want to duplicate the results you achieve with your calculations below, you can do so by simply replacing all indices Q by 1 (the last index) in the definitions of f.s and f'.s. This would duplicate exactly what you have below, but I can't imagine that this would be correct.
BTW, there is no need to get rid of the units in your routine.
Could it be that it should read "t-d[Q-c" instead of "d[Q-c"? So your function should be
If this is the case, then it could also be written as
Would the output be realistic?
That did it. What a silly mistake! Thank you again for your time Werner.
Karl Eisenacher wrote:
That did it.
Fine! So here is yet another way of writing that function:
I have another part I need help with. I am still learning the programming with Mathcad. I appreciate your help and patience!
To help explain what this is doing (this is a slightly different case, but still uses the same functions):
There is an area (As) associated with each distance (d). How they relate to the location of c dictates whether I was using the fs or f`s equations. If the area is above c, it would calculate for f's condition, and below c would calculate for fs. However, these functions are simply the Es * 0.003/c * (distance from d to c). Then my F function would be this value times the associated area (negative if below c, positive if above c). I believe the functions you posted do this in an easier manner. I am still working on plugging them into my full sheet--so have not tested yet.
The other issue I am having now is that I need to have a function that will sum the values of As that are above c. This shouldn't be too hard either, but for the life of me, I can't seem to get this to work. When I add a sum As function, it either causes an error or sums all of my As instead of the ones above c. I have attached a more complete worksheet for you.
Nevermind, got the As to sum correctly finally! Though it did not fix my end results as I had hoped. Needed to add A[Q to write each value, then was able to use the sum.
I checked the values long-hand, and the function appears to be producing the correct results. I am not sure why they do not match perfectly with the examples I was following, but they are very close and I did confirm the function is working as intended!
Also, I did revise it for using the auxiliary function including some of my other functions and that works great! Thank you again Werner.
For whatever its worth here is a routine which calculates the sum, but you had already found out yourself.
I wonder about the condition in that routine as the t is missing. Shouldn't it rather be something like "if d.Q>t-c"?
You verified that Mathcad is doing correct, but did you also check that you had set up the calculations the very same way with the same constants used as in the example you followed? As you wrote, the results are close, but the difference may be be a bit too large to be a simple numerical inaccuracy. But then I may be wrong. Maybe the author of the example you follow has used in his calculations some constants with higher precision than published.
Think you shouldn't cancel the units in most of your routines - it doesn't seem necessary and you already have to use units (e.g. in for c in the solve block).
You are absolutely right about the t-c value. I just caught this myself. However, when I altered this, my program is now giving me an error. Trying to debug this now. I am still going through and checking values for several examples now as well. I will let you know how it turns out.
I have tried to leave units in them, but I keep getting an error when I do. It is showing one of my equations is unitless and should be in pressure. However, the equation is in pressure units!
The factors 28800 and 0.04 sure are not unitless bt have dimension pressure. I have chosen ksi, please change to whatever it has to be.
Furthemore I changed the second if to an otherwise to make clear it would cover all possibilities.
Here is my check file, which includes the program solution and long-hand checks not using the program. I also have attached the example problem I was following. Unfortunately, this only gives a summary table without the intermediate steps to check where the values may deviate. However, I am confident in the check I performed by long-hand. Since the table produced on the example is from a computer program, I am a little more skeptical of the results having a typo. But there is no way that the differences I am seeing are from rounding errors either.
I am checking around to see if I can find more examples using multiple layers of reinforcement with the long-hand value break-outs to confirm the program is working as intended.
If you look at my previous screenshot, I had both the 28800 and 0.04 coefficients set to ksi and it was giving me the units error. I tried again on this check file, and for some reason, it magically works now.
If you look at my previous screenshot, I had both the 28800 and 0.04 coefficients set to ksi and it was giving me the units error. I tried again on this check file, and for some reason, it magically works now.
Yes, when I answered I didn't look at your screenshot that closely 😉
Its the otherwise which does the trick. Mathcad's logic (with the old version with the two if's) is: If both if fail (only we know that this is not possible) then the result is the last value calculated. That would be the unitless Y and so the expressions with the units throw an error. The errormessage itself is, as so often, more confusing than helpful.