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

3 次查看(过去 30 天)
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)

回答(1 个)

James Tursa
James Tursa 2019-4-11
There is no "I" variable in your code. Hence the error.
  5 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Probability Distributions 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by