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

Can Modelica solve ax+b linear equation ?

Can Modelica solve ax+b linear equation ?

model Linear

parameter Real a=2;
parameter Real b=1;

Real y;
Real x;

equation

y=a*x + b;


end Linear;

Re: Can Modelica solve ax+b linear equation ?

Yes, modelica can solve linear equations. But to solve linear equations, the number of unknowns should be equal to the number of equations. In your model x and y are the unknown variables. And "y = a*x +b" is the only equation. So there are two unknowns and only one equation. You should either define one of the two unknown variables or give another equation.
for eg:


model Linear

parameter Real a=2;
parameter Real b=1;

parameter Real y = 9;                 
Real x;

equation

y=a*x + b;


end Linear;
or


model Linear

parameter Real a=2;
parameter Real b=1;

Real y;
Real x;

equation

y=a*x + b;
y = b*x + a;


end Linear;

Re: Can Modelica solve ax+b linear equation ?

I appreciate your feedback, however I am looking to plot the evolution of y over values of x from 0 to 10 for example (y=f(x)) and not just solve the equation. So I should probably define the range of values for x. Is that doable ?

Re: Can Modelica solve ax+b linear equation ?

Maybe like that:

Code:


model linearEquation
  parameter Real a=2;
  parameter Real b=1;
  Real x = time;
  Real y;
equation
  y = a*x+b;
  annotation(experiment(StopTime = 10));
end linearEquation

so long.
Willi

Edited by: wbraun - Feb-08-17 11:22:10

Re: Can Modelica solve ax+b linear equation ?

What if I need the variable 'x' to be independent of time ?

Re: Can Modelica solve ax+b linear equation ?

But on what should the rising depend on?

You can have an input:

Code:


model linearEquation
  parameter Real a=2;
  parameter Real b=1;
  input Real u;
  Real x(start=0);
  Real y;
equation
   x = u;
   y = a*x+b;
   annotation(experiment(StopTime = 10));
end linearEquation

Or depending on time in a different order:

Code:


model linearEquation
  parameter Real a=2;
  parameter Real b=1;
  Real x(start=0);
  Real y;
equation
   der(x) = if x>=10 then 0 else 1;
  y = a*x+b;
  annotation(experiment(StopTime = 10));
end linearEquation

so long.
Willi

Edited by: wbraun - Feb-09-17 16:25:27
There are 0 guests and 0 other users also viewing this topic
You are here: