How do I type a define integral?

2 ビュー (過去 30 日間)
David Dorantes
David Dorantes 2016 年 11 月 27 日
回答済み: Star Strider 2016 年 11 月 27 日
Hello, I seem to have a problem in Matlab when I try to run a certain function, and this always appears "First input argument must be a function handle." Here's my code:
f= pi*(10^2 - 5^2);
F = integral(f,-3.53553390,3.535533906);
Im trying to calcute the volume of a toroid using this integral, 'f' was supossed to be: pi(Re^2(y) - Ri^2(y))dy. The limits been '-r' and 'r'. And to verify the volume i have V=2*pi*R*r^2.
Now.. I've been doing a little research and I think i have to use something like'@(x)' before the function. Please help.

回答 (1 件)

Star Strider
Star Strider 2016 年 11 月 27 日
See if this does what you want:
f = @(y) pi*(y.*10^2 - y.*5^2); % Create Anonymous Function, Add ‘y’
F = integral(f,-3.53553390,3.535533906); % Integrate
See the documentation on Function Basics, particularly the section on Anonymous Functions.

カテゴリ

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