Problem with exp() function

조회 수: 8 (최근 30일)
Joshua
Joshua 2022년 9월 8일
댓글: Stephen23 2022년 9월 8일
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)
ans = 2.7183
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
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
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)
ans =
2.718281828459045
exp(6)
ans =
4.034287934927351e+02
  댓글 수: 2
David Hill
David Hill 2022년 9월 8일
You should not name variables as function names.
Walter Roberson
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by