# Homework Help: Plotting several values returned by a function.

1. Oct 25, 2013

### peripatein

Hi,
1. The problem statement, all variables and given/known data
I wrote the following function for the interpolation polynomial of log(x):

function pol = Lagrange1(x)
dim1 = [1, 2, 4];
dim2 = [0, 0.693, 1.386];
pol1 = dim2(1)*(x-dim1(1))*(x-dim1(3))/[(dim1(1)-dim1(2))*(dim1(1)-dim1(3))];
pol2 = dim2(2)*(x-dim1(1))*(x-dim1(3))/[(dim1(2)-dim1(1))*(dim1(2)-dim1(3))];
pol3 = dim2(3)*(x-dim1(1))*(x-dim1(2))/[(dim1(3)-dim1(1))*(dim1(3)-dim1(2))];
pol = pol1 + pol2 + pol3;

I'd like to plot the value it returns for x = 0.01:0.01:12. How may I go about it, please? I have tried using ordinary plot(), in a loop even, to no avail.

2. Relevant equations

3. The attempt at a solution

2. Oct 25, 2013

### SteamKing

Staff Emeritus
You're going to have to provide more details. What software were you using to plot? What happened when you tried to plot? What does x = 0.01:0.01:12 mean?

3. Oct 25, 2013

### peripatein

Sorry about that. I am trying to code this using MATLAB. 0.01:0.01:12 means that x varies between 0.01 and 12 in intervals of 0.01.

4. Oct 25, 2013

### Staff: Mentor

Your function definition is missing an end statement at its end.

You need to call your Lagrange function in a for loop, something like this:
Code (Text):
j = 0
for x = .01 : .01 : 12.0
j += 1
plotVal(j) = Lagrange(x)
end

This loop should run 1200 times, once for each value of x from 0.01 to 12.0, in increments of 0.01. After the loop runs, plot the values in what I'm calling the plotVal array.