Skip to main content
1-Visitor
February 15, 2016
Solved

Function with a Vector variable

  • February 15, 2016
  • 2 replies
  • 2316 views

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

Best answer by Fred_Kohlhepp

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.

2 replies

19-Tanzanite
February 15, 2016

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.

23-Emerald I
February 15, 2016

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.

1-Visitor
February 15, 2016

Thank you every body. quick and efficient.

Regards