Error when using integral function on exponential integration
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Athul R
am 2 Jun. 2016
Beantwortet: Geoff Hayes
am 2 Jun. 2016
function = @(x) (exp(x)/x);
y = integral(function,3.5,4.5);
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 2 Jun. 2016
Athul - the error message is
function = @(x) (exp(x)/x);
Error: Function definitions are not permitted in this context.
The keyword function should be considered reserved for defining functions in your m-files and not for anonymous functions. Try using something else instead. For example,
myFunc = @(x) (exp(x)/x);
y = integral(myFunc,3.5,4.5);
You will get a different error with the above
Error using integralCalc/finalInputChecks (line 515)
Output of the function must be the same size as the input. If FUN is an array-valued
integrand, set the 'ArrayValued' option to true
When using integral, an array of elements will be passed into your anonymous function, so x will be an array. Adjust your definition to
myFunc = @(x) (exp(x)./x);
so that an element-wise division occurs.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!