cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Element of a matrix as a variable of a function ?

yeet
1-Visitor

Element of a matrix as a variable of a function ?

Hi all,

What I am tryin to achieve is to pass elements of a matrix as a variable to a function but I get the good old 'A name is required here.', please see the attachement for the snippet of my sheet. I hope experienced users can point me to the right direction.

Thanks.

ACCEPTED SOLUTION

Accepted Solutions
AndyWesterman
12-Amethyst
(To:yeet)

Because "er1[x,x" has a numeric value mathcad does not have a valid parameter to the function

What it is trying to interpret is similar to

f(2,2) := 2+2

It needs the definition to be of the form

f(a,b) := a+b

then when you call the function later

f(2,2) = it replaces the parameters a& b with the given values & return the required answer

As the snip is written , you don't need to pass any parameters, the function can access the data directly.

If , however the whole program needs the flexibility you can re-write the function in a form as attached.

regards

Andy

View solution in original post

4 REPLIES 4
AlanStevens
17-Peridot
(To:yeet)

Do it as in the attached.

Alan

I want to be able to pass each element of the matrix as variables of the function, in your example you are passing the whole matrix as a variable, am I missing something ?

AlanStevens
17-Peridot
(To:yeet)

Is there a reason why you want to pass all the elements individually, rather than the whole lot at once?

To pass them individually you have to give them all separate names (i.e. not using true subscripts).

Alan

AndyWesterman
12-Amethyst
(To:yeet)

Because "er1[x,x" has a numeric value mathcad does not have a valid parameter to the function

What it is trying to interpret is similar to

f(2,2) := 2+2

It needs the definition to be of the form

f(a,b) := a+b

then when you call the function later

f(2,2) = it replaces the parameters a& b with the given values & return the required answer

As the snip is written , you don't need to pass any parameters, the function can access the data directly.

If , however the whole program needs the flexibility you can re-write the function in a form as attached.

regards

Andy

Announcements

Top Tags