i am getting error when put definite integral of a ratio whose nemerator & denominator both are definte integral with variable limits.

11 vues (au cours des 30 derniers jours)
syms x u
lmf = @(x) exp(-x.^2);
umf = @(x) exp(-(x-5).^2);
h = @(u) exp(-u.^2);
inner_intgrl_1 = int(u.*h,[lmf umf]);
inner_intgrl_2 = int(h,[lmf umf]);
inner_intgrl_3 = inner_intgrl_1./inner_intgrl_2;
outer_intgrl_1 = integral(x.*inner_intgrl_3,x,[0 10]);
outer_intgrl_2 = integral(inner_intgrl_3,x,[0 10]);
c_jb = outer_intgrl_1/outer_intgrl_2
Error using horzcat
Nonscalar arrays of function handles are not allowed; use cell arrays instead.
Error in JB_GT2 (line 15)
inner_intgrl_1 = int(u.*h,[lmf umf]);

Réponse acceptée

Paul
Paul le 26 Nov 2025
Hi jagannath,
In the original code, lmf and umf are function handles (having nothing to do with the sym variable x), and function handles can't be concatenated into an ordinary array. Also, in the call to int the upper and lower bounds are separate, not in an array.
syms x u
lmf = exp(-x.^2);
umf = exp(-(x-5).^2);
h = exp(-u.^2);
inner_intgrl_1 = int(u*h,u,lmf,umf) % specify the variable of integration
inner_intgrl_1 = 
inner_intgrl_2 = int(h,u,lmf,umf)
inner_intgrl_2 = 
inner_intgrl_3 = inner_intgrl_1./inner_intgrl_2
inner_intgrl_3 = 
%outer_intgrl_1 = integral(x.*inner_intgrl_3,x,[0 10]);
outer_intgrl_1 = int(x*inner_intgrl_3,x,0,10)
outer_intgrl_1 = 
outer_intgrl_2 = int(inner_intgrl_3,x,0,10)
outer_intgrl_2 = 
c_jb = outer_intgrl_1/outer_intgrl_2
c_jb = 
Since a closed form solution isn't found:
vpa(c_jb)
ans = 
3.5291408653452511935031254476839
  1 commentaire
jagannath
jagannath le 26 Nov 2025

No, i found the problem lately. Actually in the outer integration it was not allowed to integrate arrays. Though thanks for reply

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by