Exponent error calculating integral.

15 Ansichten (letzte 30 Tage)
Shubhankar Jape
Shubhankar Jape am 24 Mai 2021
Kommentiert: Shubhankar Jape am 24 Mai 2021
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?

Antworten (1)

the cyclist
the cyclist am 24 Mai 2021
I expect you want
phi.^3
instead of
phi^3
inside your function fun

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by