Hi, I can't seem to get the integral function to work correctly.
syms x
z=1/(3-1)
z = 0.5000
f=@(x)(x.*exp((x.^2)-1))/sin(x)
f = function_handle with value:
@(x)(x.*exp((x.^2)-1))/sin(x)
fi=integral(f,1,3)
Error using integralCalc/finalInputChecks (line 526)
Output of the function must be the same size as the input. If FUN is an array-valued integrand, set the 'ArrayValued' option to true.

Error in integralCalc/iterateScalarValued (line 315)
finalInputChecks(x,fx);

Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);

Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);

Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);
This is my code, however the integral function keeps giving errors and I am unable to fix the problem. Could someone please help? Thanks in advance!

 採用された回答

Rik
Rik 2021 年 8 月 4 日

1 投票

The error tells you that you need to make sure f outputs the same size as the input.
f=@(x)(x.*exp((x.^2)-1))./sin(x);
% ^
% you forgot this one
fi=integral(f,1,3)
fi = 5.9621e+03

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2021 年 8 月 4 日

1 投票

f=@(x)(x.*exp((x.^2)-1))./sin(x)
Pere Garau Burguera
Pere Garau Burguera 2021 年 8 月 4 日

0 投票

The solution is given in the error message, you should use
fi=integral(f,1,3,'ArrayValued',true);
Cheers,
Pere

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2021 年 8 月 4 日

回答済み:

2021 年 8 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by