MATLAB Answers

## Why am I getting "Undefined function or variable" when I use an exponential in the function?

Asked by Nicholas Gillam

### Nicholas Gillam (view profile)

on 11 Apr 2019
Latest activity Commented on by John D'Errico

### John D'Errico (view profile)

on 11 Apr 2019
My code worked for other functions, but as soon as I use the exponential function, I am getting an error saying that "I" is undefined, and I honestly have no idea why it's giving me an error only for the exponential function.
a = 0;
b = 1;
N = 10;
f = @(x) exp(-x);
h=(b-a)/N;
j = 0;
x=linspace(a,b,N);
for i = 1:N-1
j=j+f((2*i+1)/2)*x;
end
answer1 = sum(I)

#### 0 Comments

Sign in to comment.

## 1 Answer

### James Tursa (view profile)

Answer by James Tursa

### James Tursa (view profile)

on 11 Apr 2019

There is no "I" variable in your code. Hence the error.

Nicholas Gillam

### Nicholas Gillam (view profile)

on 11 Apr 2019
Interestingly enough, I definied my f for a different problem and got the error initally stated, but the new problem doesn't have an exponential in it.
f = @(x) cos(4*cos(x)+x);
James Tursa

### James Tursa (view profile)

on 11 Apr 2019
What does the exponential have to do with your problem of "I" not being defined?
John D'Errico

### John D'Errico (view profile)

on 11 Apr 2019
I wonder if it is possible Nocholas has created a script of function named exp?

Sign in to comment.