Clear Filters
Clear Filters

It keeps giving me an error on my xlim and the graph that it gives me isn't complete

2 views (last 30 days)
Q = 9.4*10.^(-6);
q = 2.4*10.^(-5);
epsilon= 0.885*10*(-12);
R=0.1;
z=linspace(0,0.3, 1000);
F=(Q*q*z) *((1-z)/(sqrt(z.^2+R.^2)))/(2*epsilon);
plot(z,F); xlim('[1 0.3]');
xlabel('z'); ylabel('F');

Accepted Answer

Voss
Voss on 3 Mar 2024
Edited: Voss on 3 Mar 2024
xlim should be specified as a 1x2 numeric vector of increasing values, e.g.,
xlim([0.3 1]);
not as a character vector (with single-quotes)
xlim('[0.3 1]');
In this case your vector z has elements ranging from 0 to 0.3, and the plot is done with respect to z, so it's not clear why you want to set the x-limits outside the range of values in z. If you think the plot is incomplete, maybe you should change the definition of z to include higher values?
Q = 9.4e-6; % use "e" notation instead of "*10.^"
q = 2.4e-5;
% epsilon= 0.885*10*(-12); % should this one be 10.^(-12) instead of 10*(-12)?
epsilon= 0.885e-12;
R=0.1;
% z=linspace(0,0.3, 1000);
z = linspace(0,1,1000); % make z range from 0 to 1, for example
F=(Q*q*z) .*((1-z)./(sqrt(z.^2+R.^2)))/(2*epsilon);
% ^^ ^^ element-wise multiplication and division required here
plot(z,F); %xlim([0.3 1]);
xlabel('z'); ylabel('F');

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!