MATLAB Answers

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

3 views (last 30 days)
Nicholas Gillam
Nicholas Gillam on 11 Apr 2019
Commented: John D'Errico 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);
j = 0;
for i = 1:N-1
answer1 = sum(I)


Sign in to comment.

Answers (1)

James Tursa
James Tursa on 11 Apr 2019
There is no "I" variable in your code. Hence the error.


Show 2 older comments
Nicholas Gillam
Nicholas Gillam 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);

Sign in to comment.

Sign in to answer this question.