hi everybody,i`m trying to execute this code...
syms x f(x)
f(x)=exp((-x.^2)/2)
f_matlab = matlabFunction(f(x))
v1 = integral(f_matlab,1,2)
but when i do it, i get this problem
Unable to use a value of type function_handle as an index.
Error in (name of script) (line 55)
v1 = integral(f_matlab,1,2)
Does anyone know how to solve it?

 採用された回答

Steven Lord
Steven Lord 2020 年 5 月 5 日

0 投票

Rename the variable you've defined named integral so that it doesn't shadow the integral function included in MATLAB.

1 件のコメント

Raul Rodriguez
Raul Rodriguez 2020 年 5 月 5 日
Thank you very much, it runs perfect now

サインインしてコメントする。

その他の回答 (1 件)

David Hill
David Hill 2020 年 5 月 5 日

0 投票

Looks like you are trying to do numerical integration, then no need for symbolic variables.
f=@(x)exp(-x.^2/2);
v=integral(f,1,2);

1 件のコメント

Raul Rodriguez
Raul Rodriguez 2020 年 5 月 5 日
It still doesn't run :( it is part of an exercise and there are more exercises in the script , if i put it just that execrise in a separate script then it runs, but not always

サインインしてコメントする。

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by