Integral2 Error message

9 ビュー (過去 30 日間)
Kaylee Chavez
Kaylee Chavez 2021 年 2 月 10 日
コメント済み: Walter Roberson 2022 年 11 月 26 日
I am having some difficulty in verifying my answer for an iterated integral. I am looking to solve
>> F = @(x,y) x/y + y/x
F =
function_handle with value:
@(x,y)x/y+y/x
>> q = integral2(F,1,2,1,4)
After running it, I have the following error messages:
Error using integral2Calc>integral2t/tensor (line
241)
Integrand output size does not match the input
size.
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] =
integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106)
Q =
integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
>>
Is there a way to fix this? I calculated the actual answer to be about 7.27805.

採用された回答

madhan ravi
madhan ravi 2021 年 2 月 10 日
F = @(x,y) x./y + y./x
F = function_handle with value:
@(x,y)x./y+y./x
q = integral2(F,1,2,1,4)
q = 7.2780

その他の回答 (2 件)

Saumya Shil
Saumya Shil 2022 年 2 月 4 日
clear;
close;
clc;
r=1;
E= @(x) 150*pi*sin(x)/r;
Pds= @(x,y) (E^2)*(r^2)*sin(x)/120*pi;
Wr= integral2(@(x,y)Pds(x,y),0,pi,0,2*pi);
fprintf('\nPower radiated = %fW\n\n',Wr);
I am getting this message.
Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 105)
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
Error in untitled (line 9)
Wr= integral2(@(x,y)Pds(x,y),0,pi,0,2*pi);
  2 件のコメント
Steven Lord
Steven Lord 2022 年 2 月 4 日
Use element-wise operators in your integrand so your integrand will handle the (usually non-scalar) arrays that integral2 passes into it.
A = [1 2; 3 4]
A = 2×2
1 2 3 4
elementwise = A.^2
elementwise = 2×2
1 4 9 16
array = A^2 % different answer from elementwise
array = 2×2
7 10 15 22
Walter Roberson
Walter Roberson 2022 年 11 月 26 日
Pds= @(x,y) (E^2)*(r^2)*sin(x)/120*pi;
likely needs to be
Pds= @(x,y) (E(x).^2) .* (r.^2) .* sin(x) ./120 .* pi;
though I have to wonder if it is intended to be divided by (120*pi) compared to dividing by 120 and multipling the result by pi ?

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


Carlos Guerrero García
Carlos Guerrero García 2022 年 11 月 26 日
syms x y;
int(int(x/y+y/x,1,2),1,4)
ans = 
vpa(ans)
ans = 
7.2780453958794257488809372753109

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by