Home > OS >  Error : A and B must be floating-point scalars
Error : A and B must be floating-point scalars

Time:01-17

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.

CodePudding user response:

Based on our conversation in the comments, I was able to reproduce the error you saw by not making R_int_ind and R_ext_ind global at their point of initialization. Here's a simplified version of your code with this error fixed:

% Script_A_MH_L
global R_int_ind R_ext_ind % <-- Global declaration added here.
R_int_ind   = 5e-2;
R_ext_ind   = 15e-2;

pas_alpha=10;
nb_pas_al=1500;
I=[];
for ALPHA=0.1:pas_alpha:nb_pas_al;
    I(end 1)=integrantK_sup(ALPHA);
end
% integrantK_sup
function I = integrantK_sup(ALPHA)
global R_int_ind R_ext_ind
F1=@(x)x.*besselj(1,x);
I=integral(F1,double(ALPHA*R_int_ind),double(ALPHA*R_ext_ind)); % équation (70), p.2834
end

Global variables are notorious for introducing confusion. You might be better served by packaging your constants up in a struct and passing them to the functions that need them:

% Script_A_MH_L
constants.R_int_ind = 5e-2;
constants.R_ext_ind = 15e-2;

pas_alpha=10;
nb_pas_al=1500;
I=[];
for ALPHA=0.1:pas_alpha:nb_pas_al;
    I(end 1)=integrantK_sup(ALPHA,constants);
end
% integrantK_sup
function I = integrantK_sup(ALPHA,constants)
F1=@(x)x.*besselj(1,x);
I=integral(F1,double(ALPHA*constants.R_int_ind),double(ALPHA*constants.R_ext_ind)); % équation (70), p.2834
end
  • Related