模态条件MATLAB所描述的最小可能值 [英] Least Possible Value as described by Modulo Condition MATLAB

查看:94
本文介绍了模态条件MATLAB所描述的最小可能值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将要在matlab中创建一个函数,该函数将接受多个模数及其对应的余数,然后将确定适合给定模数条件的最小可能值.主要的麻烦是我不允许在matlab中使用mod()和rem()内置函数.你能帮我吗?

I am about to create a function in matlab which will accept multiple modulo and their corresponding remainders then it will determine the least possible value that will fit the given modulo conditions. Major trouble is that I am not allowed to use mod() and rem() built-in function in matlab. Can you help me with this?

推荐答案

您可以轻松创建自定义的my_modmy_rem函数,而无需使用modrem,并且可以像使用modrem.

You can easily create custom my_mod and my_rem functions without using mod and rem, and you can use these as you would use mod and rem.

function modulus = my_mod(X, Y)
if isequal(Y, 0)
    modulus = X;
elseif isequal(X, Y)
    modulus = 0;
elseif (isequal(abs(X), Inf) || isequal(abs(Y), Inf))
    modulus = NaN;
else
    modulus = X - floor(X./Y) .* Y;
end
return

function remainder = my_rem(X, Y)
if isequal(Y, 0)
    remainder = NaN;
elseif isequal(X, Y)
    remainder = 0;
elseif (isequal(abs(X), Inf) || isequal(abs(Y), Inf))
    remainder = NaN;
else
    remainder = X - fix(X./Y) .* Y;
end
return

这篇关于模态条件MATLAB所描述的最小可能值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆