integral function not working

11 ビュー (過去 30 日間)
Adrian Schmidt
Adrian Schmidt 2017 年 10 月 25 日
コメント済み: Adrian Schmidt 2017 年 10 月 25 日
Hey all,
I just started using Matlab and now I need to calculate an integral, but even the examples from the 'doc integral' page don't work when put in the command window ...
Error using integral
Too many input arguments.
or
Error using exp
Not enough input arguments.
I tried
q = integral(exp,0,1)
q = integral('exp',0,1)
fun = @(x) x.^2
q = integral(fun,0,1)
and it all gave out one of the above stated errors. I tried out a example life script from the doc site and it worked immediately and also putting the other integrals in the command window worked but after closing the life script it gave out the same errors as before ... Anybody got a clue what's going on there?
Thanks in advance!

採用された回答

Star Strider
Star Strider 2017 年 10 月 25 日
You need to create a ‘function handle’ to the exp function with an ‘@’ sign:
q = integral(@exp,0,1)
q =
1.7183
  3 件のコメント
Steven Lord
Steven Lord 2017 年 10 月 25 日
Which version of the integral function are you trying to use?
which -all integral
That code you posted works with the integral function included in MATLAB. It may not work if you've created your own integral function or downloaded one as part of someone else's code.
Adrian Schmidt
Adrian Schmidt 2017 年 10 月 25 日
Thank you Steve!
I actually had another function in the folder i was using that was called integral. Now i renamed it Matlab uses the built in integral function and everything works fine.
Thanks again!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by