英文:
Modelica playground "Internal error function lexer failed"
问题
I'm trying to use the Modelica playground to build a double pendulum model but it is erroring with "Internal error function lexer failed". How do I fix this? I assume it's a problem with my model but perhaps it's a problem with the playground? I don't know.
英文:
I'm trying to use the Modelica playground to build a double pendulum model but it is erroring with "Internal error function lexer failed". How do I fix this? I assume it's a problem with my model but perhaps it's a problem with the playground? I don't know.
constant Real speed=0.2;
constant Real gravity(unit="m/s2")=9.8 * speed;
constant Real length(unit="m")=1;
constant Real length2(unit="m")=1;
constant Real mass(unit="kg")=1;
constant Real mass2(unit="kg")=1;
Real angle(unit="rad");
Real momentum(unit="kg m/s");
Real angle2(unit="rad");
Real momentum2(unit="kg m/s");
initial equation
angle = 130 * (3.142 / 180);
momentum = 0;
angle2 = 0; // relative to vertical
momentum2 = 0;
equation
der(angle) = (6/(mass * length^2)) * ((2 * momentum - 3 * cos(angle - angle2) * momentum2)/(16 - 9 * cos(angle - angle2)^2));
der(momentum) = -0.5 * mass * length^2 * (der(angle) * der(angle2) * sin(angle - angle2) + (3 * (gravity / length) * sin(angle)));
der(angle2) = (6/(mass2 * length2^2)) * ((8 * momentum2 - 3 * cos(angle - angle2) * momentum)/(16 - 9 * cos(angle - angle2)^2));
der(momentum2) = -0.5 * mass2 * length2^2 * (-der(angle) * der(angle2) * sin(angle - angle2) + (3 * (gravity / length2) * sin(angle2)));
//annotation(experiment(StartTime=0,StopTime=200)); // todo find out how this works
答案1
得分: 1
我认为错误在于“momentum”变量的单位定义。应该是unit="kg.m/s"
而不是unit="kg m/s"
。修复后的代码如下:
constant Real speed=0.2;
constant Real gravity(unit="m/s2")=9.8 * speed;
constant Real length(unit="m")=1;
constant Real length2(unit="m")=1;
constant Real mass(unit="kg")=1;
constant Real mass2(unit="kg")=1;
Real angle(unit="rad");
Real momentum(unit="kg.m/s");
Real angle2(unit="rad");
Real momentum2(unit="kg.m/s");
initial equation
angle = 130 * (3.142 / 180);
momentum = 0;
angle2 = 0; // relative to vertical
momentum2 = 0;
equation
der(angle) = (6/(mass * length^2)) * ((2 * momentum - 3 * cos(angle - angle2) * momentum2)/(16 - 9 * cos(angle - angle2)^2));
der(momentum) = -0.5 * mass * length^2 * (der(angle) * der(angle2) * sin(angle - angle2) + (3 * (gravity / length) * sin(angle)));
der(angle2) = (6/(mass2 * length2^2)) * ((8 * momentum2 - 3 * cos(angle - angle2) * momentum)/(16 - 9 * cos(angle - angle2)^2));
der(momentum2) = -0.5 * mass2 * length2^2 * (-der(angle) * der(angle2) * sin(angle - angle2) + (3 * (gravity / length2) * sin(angle2)));
//annotation(experiment(StartTime=0,StopTime=200)); // todo find out how this works
看起来错误信息有改进的空间...
英文:
I think the error is in the unit definition of the "momentum" variables. It should be unit="kg.m/s"
instead of unit="kg m/s"
. The fixed code is:
constant Real speed=0.2;
constant Real gravity(unit="m/s2")=9.8 * speed;
constant Real length(unit="m")=1;
constant Real length2(unit="m")=1;
constant Real mass(unit="kg")=1;
constant Real mass2(unit="kg")=1;
Real angle(unit="rad");
Real momentum(unit="kg.m/s");
Real angle2(unit="rad");
Real momentum2(unit="kg.m/s");
initial equation
angle = 130 * (3.142 / 180);
momentum = 0;
angle2 = 0; // relative to vertical
momentum2 = 0;
equation
der(angle) = (6/(mass * length^2)) * ((2 * momentum - 3 * cos(angle - angle2) * momentum2)/(16 - 9 * cos(angle - angle2)^2));
der(momentum) = -0.5 * mass * length^2 * (der(angle) * der(angle2) * sin(angle - angle2) + (3 * (gravity / length) * sin(angle)));
der(angle2) = (6/(mass2 * length2^2)) * ((8 * momentum2 - 3 * cos(angle - angle2) * momentum)/(16 - 9 * cos(angle - angle2)^2));
der(momentum2) = -0.5 * mass2 * length2^2 * (-der(angle) * der(angle2) * sin(angle - angle2) + (3 * (gravity / length2) * sin(angle2)));
//annotation(experiment(StartTime=0,StopTime=200)); // todo find out how this works
Seems there is room for improvement in the error message...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论