Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

MathCAD query - Multiplication of an Array Varible 1

Status
Not open for further replies.

AMG100

Mechanical
Nov 29, 2023
8
Hi,

I was hoping someone may be able to help me with an issue I am encountering using MathCAD Prime 9 relating to the use of arrays to solve an equation which contains a variable which has multiple values.

To provide context, I am looking at analysing a simple beam with fixed ends with a moment which is applied moment at discrete positions alone the beam length. The objective is to determine see how the magnitude of the boundary reaction forces change at each moment position, which is defined by the variable (a), using the following equation taken from Roark's Formulas for Stress and Strain:

Roark_Equation_c4pgww.jpg


As (a) has multiple values I have defined these using an array i.e.

Roark_Equation_2_i7wo2r.jpg


For some reason rather than providing a number of answers for (Ra) in the form of an array for each defined value of (a) the equation returns single scalar number which appears to occur on account of the equation involving the multiplication of the array variable (a). Can anyone advise as to how I can instruct the software to provide an answer in the form of an array for rather than a scalar quantity?

Any advice greatly received!
 
Replies continue below

Recommended for you

First, this being a Mathcad question, it should have been posted in forum552.

When you multiply two matrices like you're doing, Mathcad assumes you want the dot product of said matrices, which is a scalar. If you want to evaluate the equation element wise, then you need to vectorize the equation. Highlight the entire right side of your Ra equation and then either:
[ul]
[li]Go to "Matrices/Tables" ribbon > Vector/Matrix Operators > Vectorization (V with an arrow over it)[/li]
[li]Press CTRL, Shift, ^ on the keyboard
[/li]
[/ul]
 
is Ra defined as an array ?

I'd also simplify the equation so that it is the simple sum of terms ... ka*(L-a) = kaL -ka^2
or create array b = L-a, Ra = ka*b
The equation is not "really" the multiplication of matrices, but the multiplication of arrays (but not the matrix multiplication of arrays).
the matrix multiplication of arrays says a row array times a column array = a constant (a1*b1+a2*b2+ ...)
but here we want Ra(1) = ka(1)*[L-a(1)].

maybe you can do this in a "DO loop" ?
i = 1
10 ai = a(i)
Ra(i) = k*ai*(L-ai)
i = i+1
if i>imax leave, if not goto 10

"Hoffen wir mal, dass alles gut geht !"
General Paulus, Nov 1942, outside Stalingrad after the launch of Operation Uranus.
 
Place the matrix a before the equation Ra. Before the matrix a, define a column matrix for a variable, such as i=0…3. Then, for the equation Ra, define Ra as Rai, where i is to represent the place in the column matrix, and do the same thing for a in the equation.
 
no, surely not ? multiply "Ra" but "a" ? then multiply the RHS by "a" as well, no ?

it's a long time since I've used MathCad ...
if "a" is an array, is (L-a) also an array ? (should be) I can't see that you would need to define it as such ? (I'd've thought if you define "a" as an array and L as a scalar, then it should understand L-a.)
if "Ra" is an array, as Ra = ka is, do you need to define Ra as an array ? (I think so)

if you rewrote the expression as Ra = kLa-ka^2 then this is simple math (as opposed to matrix multiplication) ... k is scalar, L is scalar, a is an array, Ra is an array.

no?

"Hoffen wir mal, dass alles gut geht !"
General Paulus, Nov 1942, outside Stalingrad after the launch of Operation Uranus.
 
do to this expression in matrix math, the 1st term on the RHS "(6...)" needs to be a diagonal matrix (with null values off the diagonal).

if you multiply two column arrays you get a scalar (a1*b1)

it's a while since I've used MathCad, so I'd run some tests ...

if "a" is an array, is L-a also an array without being defined as such ?

is it enough to define "Ra" as an array to have MathCad understand what you are trying to do ?

if you reformed your expression to Ra = kLa-ka^2 I'm sure it would understand (but maybe you need to define "Ra" as an array ?)

"Hoffen wir mal, dass alles gut geht !"
General Paulus, Nov 1942, outside Stalingrad after the launch of Operation Uranus.
 
If a is a column array and all other variables are constant, then we will have the following,
Ran = k.L.an - k.(an)^2.
Therefore
Ra0 = k.L.a0 - k.(a0)^2
Ra1 = k.L.a1 - k.(a1)^2 etc

For each value given in a, in location n, we will have a corresponding Ra value in location n. This way you use each value in a only, not the array as a whole.
 
yeah, that was my suggestion for a DO loop.

But "surely" if Ra is defined as an array then MathCad will understand Ra(i) = (k*a(i))*(L-a(i)) ... no??

"Hoffen wir mal, dass alles gut geht !"
General Paulus, Nov 1942, outside Stalingrad after the launch of Operation Uranus.
 
I must admit, I like using functions in mathcad, especially in cases such as SF and BM equations, where the equation can be set as functions, such as BM(x). Thing is, defining an equation in such a way, x is an undefined variable. Such an equation is great for graphing, defining the x input later, or doing things such as SF(x)=dBM(x)/dx. If your inputs are defined values, such as the array ’a’, I find using discrete equations rather than functions more useful.
 
Here's an example of what I described above, done in Mathcad Prime (what OP is using):

MathcadVectorize_ozgtoi.png


Ra1 shows what I believe is the problem that OP is having, while Ra2 shows the vectorized version that evaluates the equation element-wise (which I believe is what OP wants to do). I'm sure there's plenty of other ways to do it, but this is very simple and fast.
 
The attachment shows an example. As said, there's many ways of doing it. One thing I would recommend, if possible, use units. Many-a-time has someone asked me to check their calcs as the result looks wrong. Use of units would have shown there was an error.
 
 https://files.engineering.com/getfile.aspx?folder=869c0b00-7fda-422e-93e2-9030efd09ee9&file=equation.pdf
Stress_Eng: your example is much simpler than I thought it was based on your other posts. I kind of like it better than my approach since it looks like it could give you more control if needed (since you can specify the indices individually on each matrix/array).

Sidenote for OP: if you need to learn how to implement Stress_eng's example in Prime (like I did):
 
yes ! That (SE's post @19:23) correctly expressed the intension.

"Hoffen wir mal, dass alles gut geht !"
General Paulus, Nov 1942, outside Stalingrad after the launch of Operation Uranus.
 
Agreed that simply checking units can reveal a lot of problems, I just left them out of my example since it doesn't affect the math, although you're right it could make things clearer.
 
The approach has proven to be effective, even when you’re dealing with an equation involving an m,n matrix. You can define a row by using i=0…m and column j=0…n.
 
yes ... "a" is scalar, "ai" is an array, aij is a matrix element.

i think maybe part of the problem is MathCad is too tolerant to input "errors". if "a" is defined as an array then an equation using "a" should give an error code "scalar? vector?" prompting the user to change to "ai", then the next error would be "Ra" ... scalar? vector? (needs to be array, Rai)



"Hoffen wir mal, dass alles gut geht !"
General Paulus, Nov 1942, outside Stalingrad after the launch of Operation Uranus.
 
Thanks for the responses all, in this case the recommendation provided by Stick seemed to do the trick nicely (i.e. to 'vectorise' the equation) and negated a lot of unnecessary duplication which was great. Next time I'll be sure to post to the correct forum though as i didn't realise there was one dedicated to software queries, very useful resource. Thanks again...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor