Using the Integral-function

Hi, I have a problem using the function integral on Matlab R2018b.
The error is: Too many Input arguments.
function [t]=schwingungsdauerK6_A3(L,phi0)
g=9.81;
k=sin((phi0)./2);
koeff=4*sqrt(L./g);
fun=@(x) 1./(sqrt(1-(k.*(sin(x))).^2));
u=integral(fun,0,(2*pi));
t=koeff.*u
end
and I start it with this script.. for example
L=9.81
phi0 =30 degree
disp('Schwingungsdauer bei phi0= 30Grad');
erg=schwingungsdauerK6_A3(9.81,30);
fprintf('Schwingungsdauer beträgt %.2f sec',erg);
Can anyone tell my where my mistake is?

回答 (3 件)

madhan ravi
madhan ravi 2018 年 11 月 23 日
編集済み: madhan ravi 2018 年 11 月 24 日

0 投票

Bitte ausprobieren:
L=9.81
phi0 =30 %degree
disp('Schwingungsdauer bei phi0= 30Grad');
erg=schwingungsdauerK6_A3(9.81,30); %function call
fprintf('Schwingungsdauer beträgt %.2f sec\n',erg);
function [t]=schwingungsdauerK6_A3(L,phi0) %function definition
g=9.81;
k=sind((phi0)./2);
koeff=4*sqrt(L./g);
fun=@(x) 1./(sqrt(1-(k.*(sin(x))).^2));
u=integral(fun,0,(2*pi));
t=koeff.*u
end
command window:
>> COMMUNITY
L =
9.8100
phi0 =
30
Schwingungsdauer bei phi0= 30Grad
t =
25.5703
Schwingungsdauer beträgt 25.57 sec
>>

8 件のコメント

Torsten
Torsten 2018 年 11 月 23 日
k = sind(phi0/2);
madhan ravi
madhan ravi 2018 年 11 月 23 日
Thanks Torsten corrected it
madhan ravi
madhan ravi 2018 年 11 月 24 日
編集済み: madhan ravi 2018 年 11 月 24 日
it doesn't work
doesn't explain anything what error message are you getting ? paste the complete error code . See edited answer I am able to get the answer without any errors.
Matthias Radspieler
Matthias Radspieler 2018 年 11 月 24 日
Yes, I edited the error massage. So it seems, that it is an specific problem, maybe wrong settings?
madhan ravi
madhan ravi 2018 年 11 月 24 日
編集済み: madhan ravi 2018 年 11 月 24 日
try clear all at the very beginning and try again if not do the below:
type
whos integral %in command window
which integral -all
Matthias Radspieler
Matthias Radspieler 2018 年 11 月 24 日
編集済み: Matthias Radspieler 2018 年 11 月 24 日
>> whos integral
>> which integral -all
C:\Users\Matthias\Documents\MATLAB\integral.m
C:\Program Files\MATLAB\R2018b\toolbox\matlab\funfun\integral.m % Shadowed
>>
.. I don´t any answer from Matlab for 'whos integral'.
madhan ravi
madhan ravi 2018 年 11 月 24 日
C:\Program Files\MATLAB\R2018b\toolbox\matlab\funfun\integral.m % Shadowed
As the message clearly says that you have some file with the name of integral please remove it or rename because it's shadowing the in-built function integral
madhan ravi
madhan ravi 2018 年 11 月 24 日
if it solved your query make sure to accept my answer!

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

Matthias Radspieler
Matthias Radspieler 2018 年 11 月 24 日
編集済み: Matthias Radspieler 2018 年 11 月 24 日

0 投票

Thanks for your help, but it still doesn´t work.
I don´t know, where the problem is..
Error using integral
Too many input arguments.
Error in schwingungsdauerK6_A3 (line 12)
u=integral(fun,0,(2*pi));
Error in K6_A3_global (line 18)
erg=schwingungsdauerK6_A3(9.81,30); %function call

1 件のコメント

Star Strider
Star Strider 2018 年 11 月 24 日
This is the problem:
C:\Users\Matthias\Documents\MATLAB\integral.m
The solution is to rename your function to something that is meaningful to you and does not overshadow any built-in MATLAB functions.

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

Matthias Radspieler
Matthias Radspieler 2018 年 11 月 24 日

0 投票

Thank you so much for your help. Now it works perfectly! That was incredibly stupid of me.

1 件のコメント

Star Strider
Star Strider 2018 年 11 月 24 日
Not stupid. Just human!

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

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

タグ

質問済み:

2018 年 11 月 23 日

コメント済み:

2018 年 11 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by