为什么我的等式给出了错误的结果?
问题描述:
为什么我仍然得到1.0以上的值?为什么我的等式给出了错误的结果?
当试图实现这个图:
使用this网站给我提供两条线/
\
这是y = (1/3)x + 1
或y = (-1/3)x + 1
分别时,我把它放在这样的简单的数学公式:
for (int i = 0; i < 50; i++)
{
input = GenerateRandom(-3.0, 3.0); // this function works fine
output = FuzzyFunction(input); // get crisp outputs
std::cout << "input: " << input << " - output: " << output << " \n";
}
// stuff
double FuzzyFunction(double inputVal)
{
outputVal = (1.0/3) * inputVal + 1;
return outputVal;
}
然后输出是这样的:
答
斜率为正的投入应该是否定的:
double FuzzyFunction(double inputVal)
{
if (inputVal < 0)
outputVal = (1.0/3) * inputVal + 1;
else
outputVal = (-1.0/3) * inputVal + 1;
return outputVal;
}
你可以包括一些预期输出的例子吗? –
为什么你会期望一个正数PLUS ONE比任何一个少? –
该功能完全按照您所说的进行。看第一行,'input = 2.74548'。乘以1.0/3,然后做'+ 1',得到'1.91516'。如果你不想获得'1.91516',那么你必须在函数中使用不同的输入或不同的方程... –