フィルターのクリア

Not enough input arguments error/ int command/ integral calculation

3 ビュー (過去 30 日間)
Efrat Hazan Elimelech
Efrat Hazan Elimelech 2022 年 12 月 15 日
Hi,
I'm trying to calculate very simple integral, and don't understand why I get this error..
Aside from practical help I'd like to understand why this error shows up.
The script is:
integral_1=int(int_1,x1,0,pi/2);
integral_2=int(int_2,x2,0,3);
function f1=int_1(x1)
f1=8+4.*cos(x1);
end
function f2=int_2(x2)
f2=1-exp(-x2);
end

採用された回答

Bora Eryilmaz
Bora Eryilmaz 2022 年 12 月 15 日
編集済み: Bora Eryilmaz 2022 年 12 月 15 日
Use the integral command, not int. The integral command does numerical integration. The int command is for symbolic integration. Also use "@" in front of the function names to pass their function handles to the integral function.
integral_1=integral(@int_1,0,pi/2)
integral_1 = 16.5664
integral_2=integral(@int_2,0,3)
integral_2 = 2.0498
function f1 = int_1(x1)
f1 = 8+4.*cos(x1);
end
function f2 = int_2(x2)
f2 = 1-exp(-x2);
end

その他の回答 (1 件)

Cris LaPierre
Cris LaPierre 2022 年 12 月 15 日
編集済み: Cris LaPierre 2022 年 12 月 15 日
int is for symbolic integration. See Bora's answer if you want to perform numerical integration.
The error is because of how you have defined your integration functions. The integration function can't have inputs. It is probably easier if you define your functions as symbolic functions. You also need to declare your integrabtion variables as symbolic.
syms x1 x2
int_1(x1) = 8+4.*cos(x1);
int_2(x2) = 1-exp(-x2);
integral_1=int(int_1,x1,0,pi/2)
integral_1 = 
integral_2=int(int_2,x2,0,3)
integral_2 = 

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by