Skip to main content
1-Visitor
April 2, 2014
Question

Plot a function with a vector as its input variable

  • April 2, 2014
  • 2 replies
  • 11937 views

Hi,

I would like to plot a function, say y(x), that depends on x and another independent variable, say a vector ab that has the same size as x. The equation looks like this:

y(x): x +ab;

I have made a simple plot in the attached worksheet. Anybody can lend a helping hand?

Bests,

Newin

2 replies

19-Tanzanite
April 2, 2014

As in the attached?

Alan

1-Visitor
April 2, 2014

Hi Alan,

Many thanks! But what if x can't be expressed as a linear function of c (or last(ab))? For example it x is not equally spaced? The only condition I have is that for each value of x there is a particular value of ab.

Newin

19-Tanzanite
April 2, 2014

new jap wrote:

Hi Alan,

Many thanks! But what if x can't be expressed as a linear function of c (or last(ab))? For example it x is not equally spaced? The only condition I have is that for each value of x there is a particular value of ab.

Newin

I didn't suggest the relationship was a linear function - just some, possibly incredibly complicated, function. But, it doesn't really matter; as long as you have the values you can do the plotting!

Alan

25-Diamond I
April 2, 2014

x has to be a vector, not a range variable to make this work.

Guess you could use vectorization to advantage here.

Look if the attached helps.

1-Visitor
April 2, 2014

Loving that trick with the range variable.

25-Diamond I
April 2, 2014

Yes, its cute. But as to best of my knowledge its undocumented (I learned about it here in this forum, where else?) there is no guarantee it will work in future versions the same way. Also it may not work in older MC versions as inline evaluation was introduced rather late.

The distinction between range and vector has always caused confusion. I wish we could use just one for everything like in SMath. Backward compatibility might be the problem here but then, maybe even not.