Community Tip - You can change your system assigned username to something more personal in your community settings. X
Would someone please tell me why when I enter unit for the vectors, it doesn't like it? I watched this video Assigning Units to Vectors and Matrices in Mathcad Prime (youtube.com) and that's what I'm doing.
Thanks,
Solved! Go to Solution.
Your worksheet doesn't show your problem, but I'm guessing you're trying to assign units to alpha?
If so, then the problem is the string header.
Stuart
That was my initial attempt but I couldn't get the submatrix arguments right
To extract the numbers from matrix X, call the submatrix function. The arguments for submatrix are as follows: the name of the matrix, the indices of the first and of the last rows to extract, the indices of the first and of the last columns to extract
a: = submatrix (name of matrix, the indices of the first and last rows to extract, indices of the first and last columns to extract)
a = submatrix( x, row 1, to row last(of matrix X), column 0, to column 0 , column 0)
Readexcel for "Sheet1!A2:C92" is more easy to get values only.
Stuart
Thats because of different labels. The built in function is labelled "Function", while the variable is labelled "Variable".
They both can co-exist, but whenever you write "matrix" after you defined the variable, Prime assumes that you mean your variable and not the built-in function. You would have to re-label as "Function" to have access to the built-in function.
As this can be very cumbersome and confusing, I highly second your advice not to use names of built-in function as variable or user-defined function names. BTW, a user-defined function is also automatically labelled "Variable" ad so can also coexist with a built-in one.
So then why do I need to define the units as such?
I'm afraid this will create errors down the line.
without that definition, this is still after doing submatrix as you advised.
And for it to work I need to extract just the column from excel, then extract a submatrix from that same column?
I can't extract the matrix, and then a submatrix column from that matrix.
Thanks,
I can't extract the matrix, and then a submatrix column from that matrix.
I am not sure which problem you experience.
Like Stuart i cannot see the error ("when I enter unit for the vectors, it doesn't like it") you described in your initial posting.
In one of the screenshots you posted it can be seen m:=rows(matrix)=0 which usually means thats matrix is just a normal scalar variable. The matrix seems to be named "X" in he screen shot.
Your "submatrix" command fails because "last" can only be applied to vectors (n x 1 matrices). You would have to use "last(X^<0>)", where "X^<0>" should denote the first column of your matrix X.
If you experience still other problems please describe them in more detail.
I attach a sheet where I extracted the alpha column, stripped the header and added the unit centimeter.
Done on the vector alpha you already extracted and then directly from the matrix.
If you will never change the value of ORIGIN from 0 to something else, you sure can make the expression a bit shorter by directly using that number.
EDIT: From re-reading what you wrote I would guess that the faulty use of "last" with a matrix as argument was the reason for the confusion?
BTW, instead of last(matrix^<ORIGIN>) you could also use ORIGIN+rows(matrix)-1 for the very same result.
Thank you, I have to update my version to be able to open this.
You didn't tell us which version of Prime you are using.
But you should be able to grasp all thats needed from the screenshots I posted.
Basically your fault was just to use the "last" function with a matrix as its argument for which "last" unfortunately wasn't created.
@cadtelsim wrote:
So then why do I need to define the units as such?
I'm afraid this will create errors down the line.
without that definition, this is still after doing submatrix as you advised.
Your Excel worksheet header gives the unit of alpha as "/cm", which I assume means 1/cm.
You probably already know this quite well, but ... If you were to multiply alpha by ft (feet) or ns (nanosecond), Mathcad would internally convert the quantity into metres and seconds and adjust the numerical value accordingly. When you evaluate the quantity it will display in SI units. Typing the correct unit in (totally replacing the initially displayed SI unit) changes the numerical value accordingly.
Mathcad treats 1/cm the same way. That is why after multiplying alpha by 1/cm, you see 1.73 x 10^8 1/m but 1.73 x 10^6 1/cm ... the 1/cm has rescaled the numerical value of the quantity, and it matches the numerical value shown in your Excel worksheet.
You need to multiply lambda by nm to get the correct units (as indicated by the column header)
So if there are problems further downstream then it means there is likely a problem with your equations/formulae/etc. A common cause of such problems is a constant that was derived using non-SI units and hasn't been recalculated for SI units, or not scaled properly for multiples of SI units (eg, an eqn assumes mm).
As Tetsuo points out, if *you* aren't too bothered about importing the header row, then you can specify the input range as "Sheet1!A2:C92". However, it's often useful to import it anyway, as it allows you or a reviewer to check that the correct units were applied to all input variables
Stuart
@cadtelsim wrote:
And for it to work I need to extract just the column from excel, then extract a submatrix from that same column?
I can't extract the matrix, and then a submatrix column from that matrix.
Thanks,
The need to extract or remove the first row of a matrix is such a common task that it is worthwhile writing functions to do just that and keeping them in your default template.
Stuart
How does that help? From my quick read of the Excel Component Help. You've got to read an external Excel worksheet into a Mathcad variable before you pass it to an Excel Component via the Input section, then manipulate the data within the Excel Component, adding units to the data in the Output section before it gets passed back to the Mathcad worksheet.
It seems like a lot of work - and space on the Mathcad worksheet - for doing a task that can be done directly on the Excel data variable in the Mathcad workbook.
Or is there some advantage that I'm not seeing? (HIghly likely, as I don't think I've ever used an Excel Component)
Stuart
The advantage is that I don't want to see this equation in Excel.
Is that considered compelling enough?
@cadtelsim wrote:
The advantage is that I don't want to see this equation in Excel.
Is that considered compelling enough?
Meh, personal preference. Seen worse. 🙂
(And debugged worse!)
But, getting back to the original question in context, how does using an Excel Component make it any easier to remove a row from a matrix the OP needs to import anyway (and then still having to add units to the resulting vector, anyway)? A simple submatrix would seem to do the job without invoking the Excel Monster's name and summoning it forth.
Stuart
I guess that @cadtelsim did not notice that your question "How does that help?" was addressed to @ppal , who provided the link to a thread which was about the cumbersome Excel component moloch which sure is not appropriate here 😉
I don't think @cadtelsim was considering using the Excel component instead of READEXCEL.
Look like the whole long thread is simply due to a misunderstanding of the “last” function, which only accepts vectors but not general matrices as arguments.
@Werner_E wrote:
I guess that @cadtelsim did not notice that your question "How does that help?" was addressed to @ppal , who provided the link to a thread which was about the cumbersome Excel component moloch which sure is not appropriate here 😉
I don't think @cadtelsim was considering using the Excel component instead of READEXCEL.
Look like the whole long thread is simply due to a misunderstanding of the “last” function, which only accepts vectors but not general matrices as arguments.
Yes, you're right. I'm sorry to say that didn't notice that @cadtelsim was replying to @ppal's message. So, due apologies to @cadtelsim! However, I have seen worse in Excel worksheets and there isn't enough eye bleach to scrub the sight away.
Stuart
Thank you @Werner_E , that is correct, I did not notice that, thank you for your correction, my apologies too, I appreciate everyone's help and response and learn as much as I can from every post Wheater cumbersome or streamlined.
Will this work?
Yes, this is what I was hoping to learn to do. Thank you very much for your help.
So, it works, but when I enter the unit, gives an error
Don't use inline evaluation (the = after the definition.
Define the variable and in a separete region write lambda = (without "i").
personally I would prefer not to have to define a range variable "i" as in my answer above.
Simply use the "last" function on a vector or use "rows(x)-1" as described above.
This I could do, but could you tell me why the unit doesn't work?
Again - don't use inline evaluation.
Evaluate lambda in a separate region.
I think just using the submatrix command with the correct usage of "last" would be easier ...
This time I opened your sheet (which again did not show what your screenshot showed!!) with Prime 9
Got it, just got Prime 10. too. thank you for your help and patience.
You have to type the nm in the answer
@cadtelsim wrote:
This I could do, but could you tell me why the unit doesn't work?
It did work. As I said in a previous message, Mathcad converts units to SI (base) units, eg metres, and displays them as such by default. You must multiply by the unit in which you want to see the result.
Stuart
@cadtelsim wrote:
This I could do, but could you tell me why the unit doesn't work?
Now that I've downloaded the worksheet you attached to your message and am looking at your worksheet and message in daylight instead of at zero dark o'clock, I've noticed the disparity between what your posted worksheet contains and what you show above.
The way you've used the range variable also points to other complications.
Attached is a worksheet that hopefully reflects the screenshot I posted. Note that I keep your original worksheet and .xlsx files in the same local directory, hence the path change in the READEXCEL function argument.
Stuart