I'm trying to get this plot to show me a function I can code in desmos, but is giving me the wrong plot in matlab. Any help would be appreciated

7 views (last 30 days)
clc, close all, clear vars
% Pieces of the function
Q = 9.4*10^-6; % C
q = 2.4*10^-5; % C
e = 8.854*10^-12; % C^2/(Nm^2): permittivity constant
F = 0.3; % Force, newtons
R = 0.1; % radius, m
z = -0.1:0.01:0.5;
force = @(z) Q*q.*z/(2*e)*(1-z/sqrt(z.^2 + R^2))-F;
plot(z, force(z), 'g', 'LineWidth', 2);
hold on
yline(0, 'r', 'LineWidth', 2);
grid on
xlabel('Distance (m)','FontSize',14);
ylabel('Force', 'FontSize',14);
title('Force vs Distance, problem 1a')
lgd = legend({'Force/Distance', 'Force at 0.3 N'},'Fontsize', 14, 'LineWidth', 1.1);

Accepted Answer

Walter Roberson
Walter Roberson on 7 Mar 2024
clc, close all, clear vars
% Pieces of the function
Q = 9.4*10^-6; % C
q = 2.4*10^-5; % C
e = 8.854*10^-12; % C^2/(Nm^2): permittivity constant
F = 0.3; % Force, newtons
R = 0.1; % radius, m
z = -0.1:0.01:0.5;
force = @(z) Q*q.*z/(2*e).*(1-z./sqrt(z.^2 + R^2))-F;
plot(z, force(z), 'g', 'LineWidth', 2);
hold on
yline(0, 'r', 'LineWidth', 2);
grid on
xlabel('Distance (m)','FontSize',14);
ylabel('Force', 'FontSize',14);
title('Force vs Distance, problem 1a')
lgd = legend({'Force/Distance', 'Force at 0.3 N'},'Fontsize', 14, 'LineWidth', 1.1);

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!