필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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.radius = 0.03;
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
Dyuman Joshi
Dyuman Joshi 2023년 12월 18일
There are many undefined parameters in the code, so we can not run your code to reproduce the result you got.
Matt
Matt 2023년 12월 18일
편집: Matt 2023년 12월 18일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 12월 18일
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.radius = 0.03;
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by