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
Why does this not work?
See what is in red in the attached file.
Renwick Preston wrote:
Why does this not work?
See what is in red in the attached file.
1. Because although you allocated zzi values for i from 100 to 1000, Mathcad automatically created a vector going from 0 to 1000. Because you didn't specify values for i going from 0 to 99 Mathcad set them to zero. Your attempted calculation then threw up a divide by zero error.
2. Better to supply the Mathcad worksheet than a pdf.
Alan
Ok...I changed i to 1..100 and it still doesn't work.
See attached.
Renwick Preston wrote:
Ok...I changed i to 1..100 and it still doesn't work.
See attached.
That's because Mathcad starts counting at zero by default. You can change the origin if you want to. If you are only interested in i from 100 nto 1000 and then you could set ORIGIN:=100. (This is possible, but unusual! I often set ORIGIN:=1).
Alan
This is what I don't understand about MathCad...
Why can't it adapt? If I give the interval as 100 to 1000 why can't it just use that interval? Why does it insist on using 0 as the beginning number? I feel as if I'm in a strait jacket when using this program.
I mean...if I'm programming in C or Pascal and I tell the function to iterate over a certain interval it doesn't say "whoa, buddy, I insist on starting at 0!"
Message was edited by: Renwick Preston
I spoke too soon! Although what I said was true, your calculation of X didn't involve a division by the zero values of the vector zz! There was some sort of corruption in the calculation of zz. Delete zz and X and re-specify them and it should work ok. (That's why it's important to supply the worksheet - this wasn't obvious from the pdf).
Alan
Nope! It's not corrupted. You've used the wrong sort of subscript! For proper subscripts use the [ key. That is, zz[i will give you proper subscripts. You did zz.i which gives you a cosmetic subscript (ie it's just part of the name).
Alan
Hi
its possible to set up any range you want as:
start_value , first_step ; final value
Mathcad simply assumes the first step is an increment of 1 (usually) if you don't specify it.
regards
Andy
I think the complaint is about indexing. Mathcad has no capability to specify individual index ranges for an array, unlink some languages. However, many languages do not offer this capability, including some matrix languages (I can't remember, but I think Matlab normally uses 1 and doesn't allow any other base ... perhaps a Matlabber can comment).
Part of the request for a multi-dimensional array (MDA) capability was the use of array-specific index ranges.
However, I stick to zero-based arrays and I've never had a particular problem adding an offset to the index - it becomes quite natural after a time.
And I'd rather have a zero-based MDA capability than none!!!!!!! (Hint, hint, hint!!!!)
Stuart
For and high level language you always will be able to find a problem - in C you have to declare the array up front or define a pointer to some indeterminate area of memory & then request a block of memory for it to point to
The first will (if memory serves) limit you to an array that starts at 0 & counts up
The second allows a more dynamic re-allocation of memory that allow the resizing of arrays (much as Mathcad does) - the down side is that you (the programmer) have to deal with the addressing of the data yourself.
If the array / matrix / vector has to start at an indefinite index it is possible (even in mathcad) with the addition of offset terms.
M(0,0) maps to M1(0 + offset1,0 + offset2) - needs a little(?) more care but not difficult.
Obviously, for the User the more complex PTC make the interpreter & the more options they give to control - the easier it makes the task of writing this type of code. BUT it will make interpretation much more complex & prone to even more odd bugs for the few special cases that it allows.
Bottom line is that you can't please all of the people all of the time...
Best regards
Andy