I want to integrate this function but I keep getting errors

1 回表示 (過去 30 日間)
adam puchalski
adam puchalski 2022 年 7 月 7 日
編集済み: Star Strider 2022 年 7 月 7 日
Here is the code
func = @(initial) L/sqrt((E*I)/(2*F)) - integral(@(theta)1./sqrt(cos(initial)-cos(theta)),initial,pi/2);
OS = fsolve(func,0.5);
o = func(OS);
aa = linspace(0,pi);%X and Y of the theoredical
yy = @(aa) integral(cos(aa)/sqrt(cos(o)-cos(aa)),aa, pi/2);
All i need is for yy to get the values of the integration for all the values of aa. It keeps saying i need a function handle but then it thinks yy is a function, and doesnt compute it. i just need the intregal of the fuction from variable aa to pi/2.

採用された回答

Star Strider
Star Strider 2022 年 7 月 7 日
Try something like this —
[L,I,E,F] = deal(rand,rand,rand,rand); % Use Correct Values
func = @(initial) L/sqrt((E*I)/(2*F)) - integral(@(theta)1./sqrt(cos(initial)-cos(theta)),initial,pi/2);
OS = fsolve(func,0.5);
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
o = func(OS)
o = 4.5196e-08
aa = linspace(0,pi);%X and Y of the theoredical
yy = @(aa) integral(@(o)cos(aa)/sqrt(cos(o)-cos(aa)),aa, pi/2, 'ArrayValued',1);
YY = arrayfun(yy, aa);
Warning: Inf or NaN value encountered.
Warning: Inf or NaN value encountered.
figure
plot(aa, real(YY), aa, imag(YY))
grid
legend('Real','Imag', 'Location','best')
.
  2 件のコメント
adam puchalski
adam puchalski 2022 年 7 月 7 日
Yes this is very helpful thank you!!
Star Strider
Star Strider 2022 年 7 月 7 日
編集済み: Star Strider 2022 年 7 月 7 日
My pleasure!

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2022 年 7 月 7 日
yy = @(aa) integral(cos(aa)/sqrt(cos(o)-cos(aa)),aa, pi/2);
When you call this function handle it will attempt to evaluate the expression cos(aa)/sqrt(cos(o)-cos(aa)) expecting to obtain a function handle. If it does then it will pass that function handle into integral as the first input.
So I think what you want to do (if the integral is supposed to be computed over the variable o) is:
yy = @(aa) integral(@(o) cos(aa)/sqrt(cos(o)-cos(aa)),aa, pi/2);
  1 件のコメント
adam puchalski
adam puchalski 2022 年 7 月 7 日
Yes you are right! Just need arguemnts at the end! thank you!

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by