Problem with fplot - doesnt plot anything but when plotting the data individually it works

1 visualización (últimos 30 días)
Matt el 18 de Dic. de 2023
Comentada: Dyuman Joshi el 18 de Dic. de 2023
Using this code, the aim is to calcuate the magnetic field produced by a solenoid within a 3D space. However, the fplot isnt working with my function, but when I substitute values into the fucntion, I get data points that make sense, and this is plotted using the for loop. Is anyone able to help fix this problem? As its an analytical solution, a function must be used to describe it. Thanks
The Code:
magnet.length = 0.25;
magnet.position = [0, 0, 0];
magnet.I = 2.50E+01;
sphere.R = 0.25;
magnet.half_length = magnet.length / 2;
mu0 = 4*pi*1e-7;
syms x x1 % constants
f_magnet(x) = (mu0 * magnet.I * (magnet.radius^2)) / (2 * ((x-x1-magnet.position(1))^2 + magnet.radius^2)^(3/2)) * 1 / magnet.length; % Biot-Savart law
B_x_magnet(x) = int(f_magnet(x), x1, -magnet.half_length, magnet.half_length); % magnitude of B within the coil (uniform)
figure()
fplot(B_x_magnet(x), [-3*sphere.R 3*sphere.R])
hold off
figure()
for x = -3*sphere.R : 0.01 : 3*sphere.R
plot(x, B_x_magnet(x), 'o')
hold on
end
When plotting data using for loop:
When plotting using fplot:
2 comentariosMostrar NingunoOcultar Ninguno
Dyuman Joshi el 18 de Dic. de 2023
There are many undefined parameters in the code, so we can not run your code to reproduce the result you got.
Matt el 18 de Dic. de 2023
Editada: Matt el 18 de Dic. de 2023
Hello, thanks for your reply, yes I have just realised that magnet.half_length and mu0 isnt included in the parameters.
magnet.half_length = magnet.length / 2;
mu0 = 4*pi*1e-7;
Thanks

Iniciar sesión para comentar.

Dyuman Joshi el 18 de Dic. de 2023
You will have to define x as a real symbolic variable (or assume that the symbolic variable 'x' is a real number).
magnet.length = 0.25;
magnet.position = [0, 0, 0];
magnet.I = 2.50E+01;
sphere.R = 0.25;
magnet.half_length = magnet.length / 2;
%% not defined, so value is assumed
mu0 = 1;
%% Define x as a real symbolic variable
syms x real
syms x1 % constants
f_magnet(x) = (mu0 * magnet.I * (magnet.radius^2)) / (2 * ((x-x1-magnet.position(1))^2 + magnet.radius^2)^(3/2)) * 1 / magnet.length % Biot-Savart law
f_magnet(x) =
B_x_magnet(x) = int(f_magnet(x), x1, -magnet.half_length, magnet.half_length) % magnitude of B within the coil (uniform)
B_x_magnet(x) =
figure()
fplot(B_x_magnet(x), [-3*sphere.R 3*sphere.R])
figure()
for x = -3*sphere.R : 0.01 : 3*sphere.R
plot(x, B_x_magnet(x), 'o')
hold on
end
3 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
Matt el 18 de Dic. de 2023
Thanks so much for the help
Dyuman Joshi el 18 de Dic. de 2023
You are welcome!

Iniciar sesión para comentar.

Categorías

Más información sobre Calculus en Help Center y File Exchange.

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by