- #1
Mindscrape
- 1,861
- 1
Does anybody know how the quadv function works in matlab? I am trying to get a plot of the on axis field of a finite solenoid, so the formula (given I didn't make some stupid mistake deriving it, which is beside the point) should be:
[tex]H(z) = \int_{-L/2}^{L/2} \mu_0 \frac{NI}{2L} \frac{R^2}{((z-z')^2 + R^2)^{(3/2)}} dz'[/tex]
So I want it to integrate for every position from 0 to 100mm. The quad integration doesn't work because I have a vector, so I thought I would use quadv with the following mfile.
%function for thin finite solenoid
function Hz = hfield(z)
N = 10; %number of turns
I = 1; %current (amps)
a = 32.5*10.^-3; %radius of coil (m)
d = (0:0.1:100)*10^-3; %axis vector (m)
L = 10*10.^-3; %length of solenoid (m)
m = 1.25663706*10^-6; %magnetic constant
Hz = (m.*N.*I.*a.^2)./((2*L.*(a.^2+(d-z).^2).^(3/2))); %field to integrate
But when I try the function call
quadv(@Hfield, -5, 5);
Matlab says that there is a problem in the subtraction of matrix dimensions, which means that it doesn't like subtracting each array array element by the variable of integration z. I figured that it would go through the integration for each element of d, and integrate z, but apparently not? Does anybody know how to get it to do what I want it to do, which is integrate each time with with the corresponding element from the distance vector? Maybe I have to make my limits arrays too.
[tex]H(z) = \int_{-L/2}^{L/2} \mu_0 \frac{NI}{2L} \frac{R^2}{((z-z')^2 + R^2)^{(3/2)}} dz'[/tex]
So I want it to integrate for every position from 0 to 100mm. The quad integration doesn't work because I have a vector, so I thought I would use quadv with the following mfile.
%function for thin finite solenoid
function Hz = hfield(z)
N = 10; %number of turns
I = 1; %current (amps)
a = 32.5*10.^-3; %radius of coil (m)
d = (0:0.1:100)*10^-3; %axis vector (m)
L = 10*10.^-3; %length of solenoid (m)
m = 1.25663706*10^-6; %magnetic constant
Hz = (m.*N.*I.*a.^2)./((2*L.*(a.^2+(d-z).^2).^(3/2))); %field to integrate
But when I try the function call
quadv(@Hfield, -5, 5);
Matlab says that there is a problem in the subtraction of matrix dimensions, which means that it doesn't like subtracting each array array element by the variable of integration z. I figured that it would go through the integration for each element of d, and integrate z, but apparently not? Does anybody know how to get it to do what I want it to do, which is integrate each time with with the corresponding element from the distance vector? Maybe I have to make my limits arrays too.
Last edited: