Error : A and B must be floating-point scalars

1 view (last 30 days)
I am trying to integrate a function between two points but I can't do it as I get the following error:
Error using integral (line 85)
A and B must be floating-point scalars.
Error in integrantK_sup (line 6)
I=integral(F1,double(ALPHA*R_int_ind),double(ALPHA*R_ext_ind)); % équation (70), p.2834
Error in Script_A_MH_L (line 228)
integ=integrantK_sup(ALPHA);
The code used is :
nb_pt_v=200; pas_v=Ep_plaque/nb_pt_v;
nb_pt_h=200; pas_h=3*R_ext_ind/nb_pt_h;
ik=1:nb_pt_h+1;
il=1:nb_pt_v+1;
r= 0 + (ik-1).*pas_h;
z= 0 - (il-1).*pas_v; [r,z]=meshgrid(r,z);
A=zeros(nb_pt_v+1,nb_pt_h+1);
pas_alpha=10;
nb_pas_al=1500;
for ALPHA=0.1:pas_alpha:nb_pas_al
integ=integrantK_sup(ALPHA);
A=integ.*pas_alpha+A;
end
The integration function integratingK_sup is defined as follows:
function integ=integrantK_sup(ALPHA)
% équation (74), p.2835
global r z R_int_ind R_ext_ind Ep_plaque Ep_ind Airgap w mur sigma_plaque
F1=@(x)x.*besselj(1,x);
I=integral(F1,double(ALPHA*R_int_ind),double(ALPHA*R_ext_ind)); % équation (70), p.2834
Alpha_1=sqrt(ALPHA^2+1j*w*mur*sigma_plaque);
aa=I.*besselj(1,ALPHA.*r).*(exp(-ALPHA*Airgap)-exp(-ALPHA*(Airgap+Ep_ind)));
bb=(ALPHA*Alpha_1*exp(2*Alpha_1*Ep_plaque).*exp(Alpha_1.*z));
cc=ALPHA*Alpha_1.*exp(-Alpha_1.*z);
dd=((ALPHA-Alpha_1)*Alpha_1+Alpha_1*(ALPHA+Alpha_1)*exp(2*Alpha_1*Ep_plaque));
integ=((1/(ALPHA^3)).*aa).*((bb+cc)/dd);
end
To execute, you must first initialise the parameters :
Ep_plaque = 5e-3;
R_plaque = 20e-2;
R_int_ind = 5e-2;
R_ext_ind = 15e-2;
Ep_ind = 2e-3;
Airgap = 2e-3;
R_air = 5*R_plaque;
H_air = 100*Ep_plaque;
mu0=4*pi*1e-7; %% Perméabilité magnétique du vide
nu0=1/mu0; %% Réluctivité magnétique du vide
mur=1e5; %% Perméabilité magnétique relative
nur=1.0/mur; %% Perméabilité magnétique du circuit magnétique
Js=5e6; %% Densité de courant source
Is = Js *((R_ext_ind-R_int_ind)*Ep_ind); %% courant source
ADirichlet=0; %% Valeurs Dirichlet du potentiel vecteur magnétique
sigma_plaque=1e6; %% Conductivité électrique du circuit magnétique
fr=50000; %% Fréquence de travail
w = 2*pi*fr ; %% Pulsation
The problem is in the integration of the function F1 between the two points ALPHA * R_int_ind and ALPHA * R_ext_ind.
  1 Comment
Adam Danz
Adam Danz on 16 Jan 2023
Edited: Adam Danz on 16 Jan 2023
Code reorganized below so that it can run and be easily copied. A different error message shows because of a difference in MATLAB releases (yours 18a, this one is 22b).
Ep_plaque = 5e-3;
R_plaque = 20e-2;
R_int_ind = 5e-2;
R_ext_ind = 15e-2;
Ep_ind = 2e-3;
Airgap = 2e-3;
R_air = 5*R_plaque;
H_air = 100*Ep_plaque;
mu0=4*pi*1e-7; %% Perméabilité magnétique du vide
nu0=1/mu0; %% Réluctivité magnétique du vide
mur=1e5; %% Perméabilité magnétique relative
nur=1.0/mur; %% Perméabilité magnétique du circuit magnétique
Js=5e6; %% Densité de courant source
Is = Js *((R_ext_ind-R_int_ind)*Ep_ind); %% courant source
ADirichlet=0; %% Valeurs Dirichlet du potentiel vecteur magnétique
sigma_plaque=1e6; %% Conductivité électrique du circuit magnétique
fr=50000; %% Fréquence de travail
w = 2*pi*fr ;
nb_pt_v=200; pas_v=Ep_plaque/nb_pt_v;
nb_pt_h=200; pas_h=3*R_ext_ind/nb_pt_h;
ik=1:nb_pt_h+1;
il=1:nb_pt_v+1;
r= 0 + (ik-1).*pas_h;
z= 0 - (il-1).*pas_v; [r,z]=meshgrid(r,z);
A=zeros(nb_pt_v+1,nb_pt_h+1);
pas_alpha=10;
nb_pas_al=1500;
for ALPHA=0.1:pas_alpha:nb_pas_al
integ=integrantK_sup(ALPHA);
A=integ.*pas_alpha+A;
end
Error using integral
Limits of integration must be double or single scalars.

Error in solution>integrantK_sup (line 38)
I=integral(F1,double(ALPHA*R_int_ind),double(ALPHA*R_ext_ind)); % équation (70), p.2834
function integ=integrantK_sup(ALPHA)
% équation (74), p.2835
global r z R_int_ind R_ext_ind Ep_plaque Ep_ind Airgap w mur sigma_plaque
F1=@(x)x.*besselj(1,x);
I=integral(F1,double(ALPHA*R_int_ind),double(ALPHA*R_ext_ind)); % équation (70), p.2834
Alpha_1=sqrt(ALPHA^2+1j*w*mur*sigma_plaque);
aa=I.*besselj(1,ALPHA.*r).*(exp(-ALPHA*Airgap)-exp(-ALPHA*(Airgap+Ep_ind)));
bb=(ALPHA*Alpha_1*exp(2*Alpha_1*Ep_plaque).*exp(Alpha_1.*z));
cc=ALPHA*Alpha_1.*exp(-Alpha_1.*z);
dd=((ALPHA-Alpha_1)*Alpha_1+Alpha_1*(ALPHA+Alpha_1)*exp(2*Alpha_1*Ep_plaque));
integ=((1/(ALPHA^3)).*aa).*((bb+cc)/dd);
end

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 16 Jan 2023
This is a lesson to avoid using global variables.
You're not using them properly here. But instead of fixing that, I'll suggest the (much) better approach: pass variables into the function rather than using global variables.
for ALPHA=0.1:pas_alpha:nb_pas_al
integ=integrantK_sup(ALPHA,r, z, R_int_ind, R_ext_ind, Ep_plaque, Ep_ind, Airgap, w, mur, sigma_plaque);
...
end
function integ=integrantK_sup(ALPHA,r, z, R_int_ind, R_ext_ind, Ep_plaque, Ep_ind, Airgap, w, mur, sigma_plaque)
% équation (74), p.2835
% global r z R_int_ind R_ext_ind Ep_plaque Ep_ind Airgap w mur sigma_plaque % REMOVE THIS
...
end

More Answers (0)

Categories

Find more on Specialized Power Systems in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!