Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

ODE in Openmodelica

ODE in Openmodelica

i have a problem ưhen i try to describe ODE
I HAVE A  ODE :
    y''  - (y'/(x-1)) = x*(x-1) with y'(2) = -1 and y(2) = 1;
how way to get a solution?????

my code:
         

Code:

model DAEexample

  Real x;
  Real y(start = 1.0);
  Real u(start = -1.0);
equation
  der(y) = u;
  der(u) - (u/(x-1)) = x*(x-1);
end DAEexample;

--------

Code:

loadFile("C:/OpenModelica1.5.0/test/test1.mo")

true

>> simulate(test1,startTime = 2.0,stopTime = 20.0)
record SimulationResult
    resultFile = "Simulation failed.
Error: Too few equations, underdetermined system. The model has 1 equation(s) and 2 variable(s)
"
end SimulationResult;

thanks for all

Edited by: phuonghoathu - Apr-06-10 21:49:53

Re: ODE in Openmodelica

Hi,

Your system is incomplete. You will need to add one more equation for x.
All models in Modelica need to be balanced, that is, the number of variables needs to be equal with the number of equations.

Cheers,
Adrian Pop/

Re: ODE in Openmodelica

adrpo,
so,how to get a solution for it????????
y''  - (y'/(x-1)) = x*(x-1) with y'(2) = -1 and y(2) = 1;

@All : I am .... so i not good at  English

Re: ODE in Openmodelica

Modelica can't give you an analytical solution.
You need to specify what x is (add x = time for example).

Re: ODE in Openmodelica

Ok thanks

plz help me again

Code:

model rocket

    parameter Real G=6.67*(10^(-11))  "gravity constant";
    parameter Real M = 59736*(10^(24)) "mass of earth";
    parameter Real m = 7.347*(10^(22)) "mass of mooth";
    parameter Real D = 384400 "distance bettwen earth and mooth(mean)";
    parameter Real V = 100000.0 "velocity of rocket";
    Real x(start = 0.0) "distance bettwen rocket and earth";
    Real y(start = V) "der of x";
equation
           der(x) = y;
           der(y)*((D-x)^2)*x =  (-1)*G*M*((D-x)^2) + G*m*x ;                 
end rocket;

where i sinulate -> error:

Code:

simulate(rocket,stopTime = 5)

record SimulationResult
    resultFile = "Simulation failed.
"
end SimulationResult;

plz .I need it soon.I don 't know what is error

Re: ODE in Openmodelica

./rocket
DASSL--  AT T (=R1) SOME ELEMENT OF WT
      In above message,  R1 =   .2220446049250E-15
DASSL--  HAS BECOME .LE. 0.0
Error, simulation stopped at time: 2.22045e-16 with idid: -3
Result written to file.

Re: ODE in Openmodelica

Thanks for all!
But I can't fix it.plz help me.
I get a other solution by ODE :

Code:

model rocket

    parameter Real G = 6.67*(10^(-11))  "gravity constant";
    parameter Real M = 59736*(10^(20)) "mass of earth";
    parameter Real m = 7.347*(10^(22)) "mass of mooth";
    parameter Real D = 384400.0 "distance betwen earth and mooth(mean)";
    parameter Real V = 50.0 "velocity of rocket";
    Real x(start = 1.0);
    Real y(start = (V/7.92));
    Real temp1 ;
    Real temp2;
equation
    temp1 = m/M;
    temp2  = D/6400;
    der(y)*((temp2-x)^2)*x*x =  -1*((temp2-x)^2) + temp1*x*x ;
    der(x) = y;   
end rocket;

it excute good and can switch to

Code:

model rocket 

    parameter Real G=6.67*(10^(-11))  "gravity constant";
    parameter Real M = 59736*(10^(24)) "mass of earth";
    parameter Real m = 7.347*(10^(22)) "mass of mooth";
    parameter Real D = 384400 "distance bettwen earth and mooth(mean)";
    parameter Real V = 100000.0 "velocity of rocket";
    Real x(start = 0.0) "distance bettwen rocket and earth";
    Real y(start = V) "der of x";
equation
           der(x) = y;
           der(y)*((D-x)^2)*x =  (-1)*G*M*((D-x)^2) + G*m*x ;                 
end rocket;

(************)


so why (************) don't run when i simulate??????It can error of modelica??????


Thanks

Re: ODE in Openmodelica

./rocket
DASSL--  AT T (=R1) SOME ELEMENT OF WT
      In above message,  R1 =   .2220446049250E-15
DASSL--  HAS BECOME .LE. 0.0
Error, simulation stopped at time: 2.22045e-16 with idid: -3


It's simple. It can't solve the equation because you made it unsolvable. You set x(start = 0), which means for the first steps:
der(y)*((D-x)^2)*x =  (-1)*G*M*((D-x)^2) + G*m*x ;
der(y)*((D-0)^2)*0 =  (-1)*G*M*((D-0)^2) + G*m*0 ;
0 = -5.8874703126643202e+29

Clearly you can't solve this.

Re: ODE in Openmodelica

ok

I will write to clean my problem!!!!!!!11

The first i have a ODE :                   => x’’  = G*M* /(x2)  + G*m*/( (D-x)2 )       , x(0) = R , x'(0) = V    

G = 6.67*(10^(-11))  "gravity constant";

M = 59736*(10^(20)) "mass of earth";

m = 7.347*(10^(22)) "mass of mooth";

D = 384400.0 "distance betwen earth and mooth(mean)";

V = 50.0 "velocity of rocket";

After i write this on modelica (**********)

Code:

model rocket

    parameter Real G = 6.67*(10^(-11))  "gravity constant";
    parameter Real M = 59736*(10^(20)) "mass of earth";
    parameter Real m = 7.347*(10^(22)) "mass of mooth";
    parameter Real D = 384400.0 "distance betwen earth and mooth(mean)";
    parameter Real V = 50.0 "velocity of rocket";
    Real x(start = 6400.0) "distance bettwen rocket and earth";
    Real y(start = V) "der of x";
    Real temp1;
    Real temp2;
equation
           temp1 =     G*M;
           temp2 = G*m;
           der(y)*(D-x)*(D-x)*x*x =  -1*temp1*(D-x)*(D-x) + temp2*x*x ;       
           der(x) = y;   
end rocket;

i simulator it -> error

But where i change it by :   y(t) = Rx(t) và u(a) = y(a*T) với t = a*T with T2 = R/g
I have new ODE :                               u’’ = -1/(u2)  + 0.012/((60 - u)2);   u(0) = 1 ;u’(0) = V*T/R

I write on modelica

Code:

model rocket


    parameter Real G = 6.67*(10^(-11))  "gravity constant";

    parameter Real M = 59736*(10^(20)) "mass of earth";

    parameter Real m = 7.347*(10^(22)) "mass of mooth";

    parameter Real D = 384400.0 "distance betwen earth and mooth(mean)";

    parameter Real V = 50.0 "velocity of rocket";

    Real x(start = 1.0);

    Real y(start = (V/7.92));

    Real temp1 ;

    Real temp2;

equation

    temp1 = m/M;

    temp2  = D/6400;

    der(y)*((temp2-x)^2)*x*x =  -1*((temp2-x)^2) + temp1*x*x ;

    der(x) = y;   

end rocket;

-> it is ok

So , why the first(**********) way was error

Re: ODE in Openmodelica

For me, the first one succeeds and the second one fails.
If I make M,m and D constant, it succeeds. So something in initialization seems to go wrong. Note that using simulate(rocket, method = "euler") works fine regardless.

Re: ODE in Openmodelica

sjoelund.se wrote:

For me, the first one succeeds and the second one fails.
If I make M,m and D constant, it succeeds. So something in initialization seems to go wrong. Note that using simulate(rocket, method = "euler") works fine regardless.

But the first falied and the second true.I can't  explain,

So something in initialization seems to go wrong

??????

Please tell me!!!!!!!!

thanks for all!!!!!!!!!!!!!

Re: ODE in Openmodelica

adrpo,

Hello,

   Actually, I want to translate a Matlab code to openmodelica

Can you help me to translate the instructions below

Code:



options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-4 1e-4 1e-4 1e-4 1e-4 ]);
[t, s]=ode45('Modello3',tspan,T0,options);

thank you in advance for your aswer

There are 0 guests and 0 other users also viewing this topic