Exponent error calculating integral.

조회 수: 2 (최근 30일)
Shubhankar Jape
Shubhankar Jape 2021년 5월 24일
댓글: Shubhankar Jape 2021년 5월 24일
I am trying to calculate the intergral of the function given below.
clc
clear all
syms rho
format long
format compact
lambda = 100;
z_0 = lambda/100; t = lambda/100;
z_1 = z_0 + t;
limit = 1000:1000:5000;
%rhol = 1:100000;
y0 = lambda/3;
for i = 1:5
fun = @(phi) cos(2*pi.*y0./lambda).*(1./(phi^3)).*besselj(0,2.*pi./lambda.*(1./phi)).*log((-z_0+sqrt(z_0.^2+(1./phi).^2))./(-z_1+sqrt(z_1.^2+(1./phi).^2)));
fun_int(i) = integral(fun,0,limit(i));
end
%t=[1:1000];
plot(limit,fun_int)
%rho = logspace(0,5,10000);
%fun_rho = fun(rho);
%plot(rho,fun_rho)
%plot(t,fun_int);
%set(gca,'xscale','log');%set(gca,'yscale','log');
%ylabel('Function(\rho)');
xlabel('phi limit');
ylabel('f(phi)');
It throws an error
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is
a scalar. To perform elementwise matrix powers, use '.^'.
Error in
diode_semilog_01>@(phi)cos(2*pi.*y0./lambda).*(1./(phi^3)).*besselj(0,2.*pi./lambda.*(1./phi)).*log((-z_0+sqrt(z_0.^2+(1./phi).^2))./(-z_1+sqrt(z_1.^2+(1./phi).^2)))
(line 15)
fun = @(phi)
cos(2*pi.*y0./lambda).*(1./(phi^3)).*besselj(0,2.*pi./lambda.*(1./phi)).*log((-z_0+sqrt(z_0.^2+(1./phi).^2))./(-z_1+sqrt(z_1.^2+(1./phi).^2)));
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
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 88)
Q = integralCalc(fun,a,b,opstruct);
Error in diode_semilog_01 (line 16)
fun_int(i) = integral(fun,0,limit(i));
Does anybody know how to fix this?

답변 (1개)

the cyclist
the cyclist 2021년 5월 24일
I expect you want
phi.^3
instead of
phi^3
inside your function fun
  댓글 수: 1
Shubhankar Jape
Shubhankar Jape 2021년 5월 24일
Oh, I see. Thanks a lot for the help!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by