demologic.m

来自「这是《Numerical Methods with MATLAB: Imple」· M 代码 · 共 43 行

M
43
字号
function demoLogic
% demoLogic  Demonstrate logical comparison operators, print results to screen

a = 2,  b = 4
aIsSmaller = a < b

bIsSmaller = b < a

a = 2;  b = 4;
aIsSmaller = a < b;
bIsSmaller = b < a;
bothTrue = aIsSmaller & bIsSmaller

eitherTrue = aIsSmaller | bIsSmaller



x=-2,  y=5
if x >= y
   c = x^2 - y;
elseif x*y > 0.0     %  make sure y/x is positive
   c = log(y/x);
end
if ~exist('c','var')
  warning('c is not defined');
else
  disp(c)
end

if x >= y
   c = x^2 - y;
elseif x*y > 0.0     %  make sure y/x is positive
   c = log(y/x);
else
   warning('either x and y are both negative or x<y');
   fprintf('x = %f    y= %f\n',x,y);
end
if ~exist('c','var')
  warning('c is not defined');
else
  disp(c)
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?