【问题标题】:How to write a Matlab program to determine the point in the square如何编写Matlab程序来确定正方形中的点
【发布时间】:2020-09-15 04:52:32
【问题描述】:

如果给定点 (x,y) 在正方形内,如何编写一个给出 1 的 Matlab 程序。如果给定点 (x,y) 在正方形的边界上,则它给出 0。如果给定点 (x,y) 在正方形之外,则给出 -1。具有角 (1,1)、(1,-1)、(-1,-1) 和 (-1,1) 的正方形。 (提示:您可以使用函数“abs”或“max”) 假设 x = 0.5; y = 0.5;

【问题讨论】:

  • 我投票结束这个问题,因为它要求解决家庭作业问题。

标签: matlab max point square


【解决方案1】:
x = 0.5;
y = 0.5;

if  max(abs(x),abs(y)) ==1
    f = 0;
elseif max(abs(x),abs(y)) > 1 
    f = -1;
else
    f = 1;
end

【讨论】:

    猜你喜欢
    • 2020-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-09
    • 2011-05-09
    • 1970-01-01
    相关资源
    最近更新 更多