Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
HI,
Could someone explain to me how to calculate the summation operator? I have attached a picture where you can see my formula. If I understand correctly, my condition formula should work like this: 0.1 + 0.2 + 0.3 + 0.4 + 0.5 = 1.5. However, Mathcad only gives 0.1. What am I doing wrong?
Solved! Go to Solution.
Ignore my previous suggestion. While on my back home, I had a "Doh!" moment. I'd temporarily forgotten that the Summation Operator automatically steps by 1. I would suggest that the j specification needs to include the step value, but I can't figure out how to include it. Hopefully, somebody will be along to say how it can be done.
In the meantime, however ...
Stuart
I’m not at my Mathcad at the moment, but try deleting the evaluation operator (= sign) after your expression and then evaluating Urms_new separately.
Stuart
Ignore my previous suggestion. While on my back home, I had a "Doh!" moment. I'd temporarily forgotten that the Summation Operator automatically steps by 1. I would suggest that the j specification needs to include the step value, but I can't figure out how to include it. Hopefully, somebody will be along to say how it can be done.
In the meantime, however ...
Stuart
thank you very much
By the same token, do you know how to get the number of rows from the matrix t? I tried using the rows(t) command, but it doesn't work, and I can't find another way
t is a range variable. A range variable holds a range definition (range operator with values). A range variable is effectively a promise to generate the specified numbers one at a time when the rv appears in an evaluation (=) or the right hand side of a definition (≔).
It is NOT a vector. Range variables and vectors have been confusing new users since time immemorial precisely because they look the same.
Note that you need to be careful using Method. Because Mathcad, like most maths apps, uses (64-bit) floating point arithmetic, you can have small internal differences from the exact decimal representation of a number. So, scaling might not give the desired exact multiples of a number. It is sometimes best to use a rounding function (eg, round!) to avoid potential issues).
There are other methods of converting, and I'm confident somebody else will be along to show them (I always use vec and have it in my default template, so I don't need to rewrite it every time or copy/paste it).
Stuart
Just some additional remarks.
Stuarts "vec" function assumes that you did not change the value of the system variable ORIGIN from the default value 0 to something else.
I, too prefer to have ORIGIN set to 0, but some people change it to ORIGIN:=1 because they want the first element in a vector to be indicated by the index 1 and not 0.
To be on the safe side you may slightly modify Stuarts function to make it immune against ORIGIN modifications
You can replace rows(t) in your formula by rows(vec(t)) and it should work OK.
Thank you for your response, but I think we didn't talk 🙂 I would like to take the number I show in the picture.
My case 'last' function not working
if I write t= I got
It look how matrix, but is not matrix
last doesn't work on t because t is *not* a vector. t is a range variable, which is quite a different beast.
A range comprises a range operator (_ , _ .. _) with values in the placeholders. When you assign a range to a variable, that variable becomes known as a range variable.
When Mathcad encounters a range variable (RV), Mathcad treats the RV like an iterator. Mathcad runs through each implied value within the range and each successive value to the user's equation(s). When you evaluate an RV, Mathcad runs through the implied sequence and prints out each value. Unfortunately, the chosen format for this action looks identical to a vector, which causes no end of confusion for new (and even experienced) users.
To find the index of the last element of t, you need to convert t to a vector. Here's one way:
A note of caution. You must use vec in a definition to get a vector result. If you look at the vec(t) evaluation, you should see that Mathcad has iterated through t, applying vec to each value it generates, producing a pseudo=vector of one-element arrays. Assigning vec(t) to a variable (t in this case) does return a vector. Rather than create a vector if all you want is the index number of the last element, you can create a function that does the job for you; variables within a function are volatile and should not affect memory use except when
actually called.
Stuart
While the range cannot be defined directly in the sum operator, we could combine its definition and the some in a self-contained two-liner
True, and that nicely hides j from the outside world.
I did a search for "summation operator step size" in the Community to see if anybody had mentioned this before. Nothing sprang to vision, but I did see that @VladimirN had posted the M11 User's Guide, so I had a look in that to see if it offered any guidance. Indeed it does:
Summation: Description: Performs iterated addition of X over i = m, m + 1, ... ,m. X can be any expression; it need not involve i but it usually does. m and n must be integers. If m = -∞ or n = ∞, the evaluation must be performed symbolically.
I'm going to guess that the changing the step size was overlooked during the revamp of the summation operator (so that "m, n are real numbers. n > m"). Restricting the step size to 1 might make sense when m and n are integers, but not so much when they're reals.
Apart from not being able to specify step sizes in the summation and product operators, my absolute number one gripe wrt to the range operator is that it butchered a number of my M11 worksheets. I used to frequently use for loop constructs such eg, for x ε 0,1,5,9 or x ε 1,3,(7,9..13),18, which M11 would happily iterate over. And I could even use a range definition directly as an parameter for a function - vec(0.1, 0.2 .. 0.9) was perfectly legal in M11..M15. Prime? Nah. I had a whine at time about it, but was inevitably ignored.
Of relevance to ranges and step sizes, is an M11 function I wrote called getrngpattern that guesses the step size. Converting to MP gives an "This expression could not be interpreted" error and pretty picture of the offending item.
I'd even long ago suggested generalizing the 'range operator' to a sequence operator. This would have the virtue of being a pathway to having an arbitrary number of function arguments - just specify what you want as a sequence and let your function internals deal with "missing" parameters. And it would allow smarter sequences, such as fitting a polynomial to a range (1, 2, 4 .. 32 would fit a parabola to the numbers (*) ... it would need thinking about to remove ambiguities, I admit. I was even more roundly ignored. Oh, another suggestion was allowing characters as well as numbers, eg "a" .. "d" would produce the values "a", "b", "c", "d".
Stuart
(*) I have a function seqfit that will do such a fit (including on strings should anyone have a reason to do so) . I've also got a function seq that will generate successive characters in a given range, and a version that will generate successive words in a restricted range (eg, "a" .. "y", "z", "aa", "ab" .. "zz", "aaa" ...
Here is a workaround, but unfortunately Prime won't allow to type in the range - we have to use copy & paste
Edited to add Mathcad worksheet.
Indeed, and that is how I get around the problem using one of my many vec implementations. But, ...
Well, well, well. Three holes in the ground ... as the saying goes. I made a discovery. I take some of my criticism back. Direct entry of range variables as a function parameter is only 3/8 broken. You can type a 1-step range operator into a function parameter if you enclose it in parentheses. You can't type a 3-place range operator into the argument position, but you can paste one into it. Go figure. Doubtless, an oversight that will soon be corrected ... ☹️
I'm not sure why I never noticed that before. In M11..M15, I routinely surrounded ranges in parentheses if they were part of a for-loop sequence or to remove ambiguity.
@DJNewman Dave, I don't know whether this (range operator arguments) might be useful to you for a Mathcad article?
Stuart
I have a set of string-specific string-to-char_vector functions available in my standard utility library. There's a simple version that pouts when it hits an illegal character, and there's a hardier version that simply shrugs and ignores such trifles. Here's an Express version.
However, I tend to either copy only what I need from the standard library to a new blank worksheet or delete everything I don't need from my default template (which includes the standard library), as that can speed up load times. So, having a more versatile vec saves faffing around deciding what to keep and what to delete.