How to integrate an array properly in matlab
Afficher commentaires plus anciens
Hello, I am trying to finish a m-file to find the inductance in 2 coils. I have finished the program to the point of integration. I believe the problem is the integration of an array. I have tried various methods such as int, trapz, and quad but all of these seem to be returning an error. I am not sure as to whether I am implementing the commands wrong or rather I have a bad equation. Here is my code
% This program finds mutual inductance for TET coil system %
% Using Neumann's definition %
% M = sqrt(ap*as)*(1/(2*pi))*(int(((cos(theta)-(d/as)*((cos(psi)*cos(phi))-(sin(psi)*sin(phi)*cos(theta))))/(R^(3/2)))*f,phi,0,2*pi))
%
% Increment angles
%psi = [0:1:90];
%theta = 0:1:90;
%phi = 0:1:90;
psi = input('Enter psi value in degrees \n')
theta = input('Enter theta value in degrees \n')
phi = input('Enter phi value in degrees \n')
% Arguments
%dim = 0:2*pi
h = input('Enter h value in mm \n')
ap = input('Enter ap value in mm \n')
as = sqrt((ap^2)-(h^2))
delta = h/ap
alpha = as/ap
d = h.*tan(phi)
Ra = (1-(cos(phi).*cos(phi).*sin(theta).*sin(theta)))
Rb = ((2)*(d/as)).*((sin(psi).*sin(phi))-(cos(psi).*cos(phi).*cos(theta)))
Rc = ((d.^2)/(as.^2))
R = sqrt(Ra+Rb+Rc)
z = delta-(alpha*sin(theta)*cos(phi))
%kprime_2 = (((1-(alpha.*R)).^2)+z.^2)/(((1+(alpha.*R)).^2+z.^2))
kprime_2a = ((1-(alpha.*R)).^2)+z.^2
kprime_2b = ((1+(alpha.*R)).^2)+z.^2
kprime_2 = kprime_2a./kprime_2b
f = -0.011*(log(kprime_2))-0.0021
integrand = ((cos(theta)-(d/as).*((cos(psi).*cos(phi))-
(sin(psi).*sin(phi).*cos(theta))))/(R.^(3/2))).*f
%integrand1 = double(int(((cos(theta)-(d/as).*((cos(psi).*cos(phi))-(sin(psi).*sin(phi).*cos(theta))))./(R.^(3/2))).*f,phi,0,2.*pi))
%integrand = double(integrand);
stuff = trapz(phi,integrand)
M = sqrt(ap.*as).*(1/(2*pi)).*stuff
I am setting psi and phi to 0 and setting theta to 0:10:90. H is usually 3 and ap is usuall 6. This gives me different error messages for each method of integration I use.
Any help would be appreciated. Thanks.
5 commentaires
Andrew Newell
le 6 Juin 2013
Are you trying to integrate over theta or phi?
Alexander Lampe
le 6 Juin 2013
Hey, I tested your script with your values psi, phi... But then "phi" and "integrand" are both scalar. Then MATLAB expects, that the second Input off trapz() is the dimension, so it needs to be an integer. Write trapz(phi,integrand,1) or rather trapz(phi,integrand,dim) and it will work. But why you use trapz() for scalar values?
Alex
Andrew Matthews
le 7 Juin 2013
Andrew Matthews
le 7 Juin 2013
Modifié(e) : Andrew Matthews
le 7 Juin 2013
Andrew Matthews
le 7 Juin 2013
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!