que consiste el error "as a function is not supported "

x=0:0.01:2
f=@(x) x.^2;
f= integral(f)
no me deja usar la funcion integral, tiene un error de Execution of script integral as a function is not supported:
C:\Users\Javier\OneDrive\Documentos\MATLAB\integral.mlx

Answers (2)

syms x
f = x^2;
I = int(f,x,0,2)
I = 
or
f=@(x) x.^2;
I = integral(f,0,2)
I = 2.6667
you named your own Livescript "integral" and it is in your current folder. When matlab encounters the call to integral() in your code, there is a specific order it searches in. It checks to see if integral is a variable in your workspace. It checks to see if you used "import" to bring it in from a package. It checks to see if the directory containing the script has a subdirectory named "private". It checks to see if there is integral.slx integral.mdl integral.p integral.m integral.mlx and probably some others (exact order might not be exactly what I listed.) Only after the current directory is searched and not found does it look in the standard directories to find matlab's own integral functions.
So the fact that you named your Livescript integral.mlx is causing your script to be found instead of the matlab integral() function. And then matlab complains because your integral.mlx is not a function.
Moral of the story: avoid naming your script the same as something that you might need to call.

Categories

Find more on MATLAB in Help Center and File Exchange

Answered:

on 15 Feb 2023

Community Treasure Hunt

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

Start Hunting!