Finite Solenoid On-Axis Field in MATLAB

In summary, the quadv function in matlab does not seem to work as expected, and may require some modification to get it to integrate for every position in the distance vector.
  • #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.
 
Last edited:
Physics news on Phys.org
  • #2
set d as a global variable. Then you do a program file that calculates the integral for a value of d, store that in a vector, increase d, integrate, etc..

So remove the line with "d" from this function file.

And also, a = 32.5*10.^-3; isn't nicer do write 3.24e-2 ?

And use the normal quad.

I have not tried this, but I think this a way you can do it.
 
  • #3
Yeah, I was afraid I might have to try something like this. The alternate method works fine, though it is inconvenient. I made this file, and everything checks out, about 2 Guass in the middle of the solenoid.

%integrate hfield for a given distance array

function [Hval] = HInt(d)

%variables to use
L = 10^-2; %length of solenoid in meters
n = length(d); %find the number of elements in d
i = 1; %loop variable
global s; %make distance element global for field function

%now that loop is primed and ready, evaluate
while (i <= n)
s = d(1,i);
Hval(1,i) = quad(@Hfield,-L/2,L/2);
i = i+1;
end
 

FAQ: Finite Solenoid On-Axis Field in MATLAB

What is a finite solenoid?

A finite solenoid is a cylindrical coil of wire with a finite length and a certain number of turns. It produces a magnetic field along its axis when an electric current is passed through it.

How can I calculate the on-axis field of a finite solenoid?

The on-axis field of a finite solenoid can be calculated using the formula B = μ0Ni/L, where B is the magnetic field, μ0 is the permeability of free space, N is the number of turns, i is the current, and L is the length of the solenoid.

Why is MATLAB commonly used for simulating the on-axis field of a finite solenoid?

MATLAB is commonly used for its powerful mathematical and numerical computation capabilities. It also has built-in functions and tools specifically designed for solving electromagnetic problems, making it a convenient tool for simulating the on-axis field of a finite solenoid.

What factors can affect the on-axis field of a finite solenoid?

The on-axis field of a finite solenoid can be affected by factors such as the number of turns, the current passing through the solenoid, the length of the solenoid, and the permeability of the material inside the solenoid.

How can I visualize the on-axis field of a finite solenoid using MATLAB?

To visualize the on-axis field of a finite solenoid using MATLAB, you can plot the magnetic field as a function of distance along the solenoid's axis. You can also use the quiver function to create a vector field plot, showing the direction and magnitude of the magnetic field at different points along the solenoid's axis.

Similar threads

Replies
8
Views
2K
Replies
1
Views
1K
Replies
2
Views
3K
Replies
1
Views
2K
Replies
1
Views
3K
Replies
5
Views
2K
Replies
3
Views
4K
Back
Top