Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

Underdertermined system of equations

asked 1 year ago

elle gravatar image

updated 1 year ago

Max Alekseyev gravatar image

Let's say we have 2 equations and 3 variables (N equations and M variables, where M > N), for example:

0.3a+0.1b+0.2*c=10 + E

0.1a+0.2b+0.3*c=11 + E

We want to find a, b, c that are in the range [0.0, 1.0] and we want to minimize the error E.

We want a smooth solutions that in this context means that if we chart a, b, c in a chart, the chart is smooth.

How this kind of problems can be approached with sagemath?

Preview: (hide)

Comments

This kind of problems can be solved with MILP - see details and examples at https://doc.sagemath.org/html/en/them...

Max Alekseyev gravatar imageMax Alekseyev ( 1 year ago )

Hello, in my case all variables are non-integer (can have decimals)

elle gravatar imageelle ( 1 year ago )

That's fine. MILP supports non-integer variables as well.

Max Alekseyev gravatar imageMax Alekseyev ( 1 year ago )

In fact it's not E which should be minimized but |E|. So the problem should receive a special formalization which can transform a minimization of an absolute value (which is not linear) in the minimization of an affine objective. This can be correctly be done as Max underline with MixedIntegerLinearProgram in SageMath. Elle if you need some help I can write the program for ypu.

Cyrille gravatar imageCyrille ( 1 year ago )

Good catch! E is actually |E|. If you have any example of how to code the system would be great!

elle gravatar imageelle ( 1 year ago )

1 Answer

Sort by » oldest newest most voted
0

answered 1 year ago

Max Alekseyev gravatar image

Here is an example, in which we use x[0], x[1], x[2] for a, b, c, and x[-1] for the (absolute) bound for errors.

milp = MixedIntegerLinearProgram(maximization=False) # we do minimization

x = milp.new_variable(real=True)
milp.set_min(x[0],0)
milp.set_min(x[1],0)
milp.set_min(x[2],0)
milp.set_max(x[0],1)
milp.set_max(x[1],1)
milp.set_max(x[2],1)

eq1 = 0.3*x[0] + 0.1*x[1] + 0.2*x[2] - 10
milp.add_constraint( eq1 <= x[-1] )
milp.add_constraint( eq1 >= -x[-1] )

eq2 = 0.1*x[0] + 0.2*x[1] + 0.3*x[2] - 11
milp.add_constraint( eq2 <= x[-1] )
milp.add_constraint( eq2 >= -x[-1] )

milp.set_objective(x[-1])    # minimize the error bound

milp.solve()
print( milp.get_values(x) )

The code produces the following result: {0: 1.0, 1: 1.0, 2: 1.0, -1: 10.4}, that is a=b=c=1.0, and the maximum error of 10.4.

Preview: (hide)
link

Comments

Thanks a lot!

I can see that f = |E|

is translated as f <= E f >= -E

but let's suppose that E=5 and f=4, the translated system of equations will be true in this case while 4 = |5| is false

elle gravatar imageelle ( 1 year ago )

Errors may differ across the equations. x[-1] bounds their absolute values from above.

Max Alekseyev gravatar imageMax Alekseyev ( 1 year ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 1 year ago

Seen: 334 times

Last updated: Apr 20 '24