
Problem with exp() function
8 次查看(过去 30 天)
显示 更早的评论
I wonder why this function exp(1), which supposedly has to give you the Euler's constant, gives me the number 1. Furthermore, whenever I put a number bigger than 1, e.g., 3, it says that the index cannot exceed the number 1.
That is, the code is the following:
exp(1)
But look at the following image:

It supposed to give me an approximation of Euler's constant.
Code Used:
exp(1)
>> ans = 1
exp(6)
Index exceeds the number of array elements. Index must not exceed 1.
Error in eulers_contant (line 2)
exp(6)
>>
I dont know what to do now.
1 个评论
Stephen23
2022-9-8
"Problem with exp() function"
There is no problem with the EXP function.
"it says that the index cannot exceed the number 1."
You defined a scalar variable named EXP:

What do you expect to happen, when you try to access the 6th element of an array that only has one element?
回答(1 个)
David Hill
2022-9-8
编辑:David Hill
2022-9-8
Make sure your clear your workspace and do not have any function names 'exp'
clear
format long
exp(1)
exp(6)
2 个评论
Walter Roberson
2022-9-8
Right, the image towards the left shows that the user had a variable named exp with a value of 1 as if they had coded
exp=(1)
instead of
exp(1)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!