间隔绘图功能

时间:2019-03-30 17:20:28

标签: matlab plot

我具有以下功能:

ySol2=(2*(x^3 + 1)^(1/2))/cos(x) +2/cos(x)

我的问题是如何在cos(x)!= 0和x> -1的约束下以1000; 5000的间隔绘制它?

1 个答案:

答案 0 :(得分:0)

也许是这样?

% your function. Note element-wise operations (.^, ./)
ySol2 = @(x) (2*(x.^3 + 1).^(1/2))./cos(x) +2./cos(x);
% your x interval, with step 0.1. Note also that the argument for 'cos' is in [rad].  
x = 1000:0.1:5000;
% calculate function values
y = ySol2(x);
% keep only non-constrained values
ind = (cos(x)~=0) | (x>-1);
x = x(ind);
y = y(ind);
% plot
figure;
plot(x,y);