- Index
- » Programming
- » Modelica Language
- » Why don't work inverse()?
Why don't work inverse()?
Why don't work inverse()?
I'm trying to start this test code with inverse()operator in OMNotebook:
Code:
function x_to_y
input Real x;
output Real y;
[b] annotation(inverse(x = y_to_x(y)));[/b]
algorithm
y := x;
end x_to_y;
function y_to_x
input Real y;
output Real x;
algorithm
x := -y;
end y_to_x;
model Test
parameter Real y = 5;
Real x;
equation
y = x_to_y(x);
end Test;
simulate(Test)
val(x, 1.)
And result = 5, but i'd like to get -5.
Similarly inverse() doesn't work in OMedit.
I use OpenModelica v1.12.0-dev-36-g9ba9c3d (64-bit).
Thanks in advance.
Re: Why don't work inverse()?
The inverse annotation is not used by OpenModelica. It solves the function numerically instead (your x_to_y function has the error; fix it and you get the expected result). If you use Inline=true, the generated code does not contain any non-linear system to solve at run-time.
- sjoelund.se
- 1700 Posts
Re: Why don't work inverse()?
sjoelund.se wrote:
The inverse annotation is not used by OpenModelica. It solves the function numerically instead (your x_to_y function has the error; fix it and you get the expected result). If you use Inline=true, the generated code does not contain any non-linear system to solve at run-time.
Thank you sjoelund.se!
No error in the function x_to_y(x). Realy I need something like what:
Code:
function x_to_y
input Real x;
output Real y;
annotation(inline = false, inverse(x = y_to_x(y)));
algorithm
y := x ^ 2;
y := sign(x) * y;
end x_to_y;
function y_to_x
input Real y;
output Real x;
algorithm
x := sqrt(abs(y));
x := sign(y) * x;
end y_to_x;
Without inverse() I'll get error: "Argument of sqrt(y) was -5 should be >= 0".
A pity that the inverse annotation is not used by OpenModelica
Re: Why don't work inverse()?
No, there really is an error in your original post. You have x_to_y mapping y:=x and y_to_x mapping x:=-y. So it is not an inverse function.
When I try your other functions, OM also solves them just fine.
- sjoelund.se
- 1700 Posts
Re: Why don't work inverse()?
sjoelund.se wrote:
No, there really is an error in your original post. You have x_to_y mapping y:=x and y_to_x mapping x:=-y. So it is not an inverse function.
When I try your other functions, OM also solves them just fine.
Yes, if in Test x > 0 OM solves it, but if x < 0 no:
reverseTest.onb
If I wrote in x_to_y() y := x, I would not have understood that inverse not working.
Re: Why don't work inverse()?
Post the model (mos-script, not onb) to https://trac.openmodelica.org/OpenModelica/newticket
It seems even with Inline=false, in this instance the function is inlined and this causes a bad equation to be generated:
x := $_signNoNull($TMP$VAR$3$0X$ABS) * abs(y ^ 0.5)
Should probably have been abs(y)^0.5 that should have been automatically generated...
- sjoelund.se
- 1700 Posts
Re: Why don't work inverse()?
sjoelund.se wrote:
Post the model (mos-script, not onb) to https://trac.openmodelica.org/OpenModelica/newticket
It seems even with Inline=false, in this instance the function is inlined and this causes a bad equation to be generated:
x := $_signNoNull($TMP$VAR$3$0X$ABS) * abs(y ^ 0.5)
Should probably have been abs(y)^0.5 that should have been automatically generated...
Many thanks, sjoelund.se
Re: Why don't work inverse()?
Is this still true in v1.14 then?
Are there plans to include this really useful feature?
- DarioMangoni
- 45 Posts
- Index
- » Programming
- » Modelica Language
- » Why don't work inverse()?