我是 Mathematica 的新手,我似乎在 Mathematica 语法中遗漏了一些东西。
我复制了下面的两个代码。
对于此示例,Print[second] 必须返回 120,但它始终为 0。
任何建议表示赞赏。
C:
int row = 4;
int column = 10;
int passenger = 5;
int luggage = 20;
int arrival = 15;
int walking = 5;
int second = 0;
int waitingtime = 0;
int _yolcu = 0;
for (int i = 0; i <row; i++)
{
waitingtime = 0;
if (_yolcu == passenger)
break;
for (int j = 0; j < column; j++)
{
if (_yolcu == passenger)
break;
_yolcu++;
if (i == 0 && j == 0){
second = second + luggage;
continue;
}
else
{
waitingtime = 0;
waitingtime =second-(j * walking + arrival * (_yolcu - 1));
if (waitingtime>= 0)
{
second = second + walking + luggage;
}
else
second = second - waitingtime+luggage;
}
}
}
数学:
row = 4;
column = 10;
passenger = 5;
luggage = 20;
arrival = 15;
walking = 5;
second = 0;
waitingtime = 0;
_yolcu = 0;
For[i = 0, i < row, i++, waitingtime = 0;
If[_yolcu == passenger, Break[],
For[j = 0, j < column, j++,
If[_yolcu == passenger, Break[], _yolcu++;
If[i == 0 && j == 0, second = second + luggage,
waitingtime = second - (j*walking + arrival*(_yolcu - 1));
If[waitingtime >= 0, second = second + walking + luggage,
second = second - waitingtime + luggage]]]]]]
Print[second]