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

Function with a Vector variable

msantarsiero
1-Newbie

Function with a Vector variable

Hello,

usually I define function as function of variables. The latter being scalar.

How can I define a function with the variable being a vector?

example

function(p):=p(1)*x+p(2)

with p being a vector

this gives me error

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions

Vectors are indexed starting at zero.  To address the first element in a vector requires a subscript using the keystroke "[".

Your sheet then will look as:

I have made the function use both p (a vector) and x.  You can put any vector (with at least two elements) into the function, and any value for x.

View solution in original post

3 REPLIES 3

function(p):=p[1*x+p[2

Note however that the default origin of vectors in Mathcad is 0, not 1, so unless you change the default then

function(p):=p[0*x+p[1

If that doesn't work, please post the worksheet.

Vectors are indexed starting at zero.  To address the first element in a vector requires a subscript using the keystroke "[".

Your sheet then will look as:

I have made the function use both p (a vector) and x.  You can put any vector (with at least two elements) into the function, and any value for x.

Thank you every body. quick and efficient.

Regards

Top Tags