How to solve a linear equation with maximum equation?

4 visualizzazioni (ultimi 30 giorni)
Hello all,
How to solve a linear equation with geometric square equation? I have a point and a direction, let's assume the starting point is (0,0) and the direction is 45 degrees above the x-axis. I am trying to find the crossing point of the line which starts at the start point and goes with the direction specified (which means in our example the line is y = x) and a square equation. The square equation for one who may not know is max(abs(x),abs(y)) = wall distance from center. So if we assume our wall distance from center is for example 50 cm. The crossing points of the linear line with the square equation in our example is (50,50) and (-50,-50) and I am looking only for the point (50,50). I thought to solve the equations and to take only the relevant point, but when I am trying to do:
syms x y;
wall_distance = 50;
sox = solve(x == y, max(abs(x),abs(y)) == wall_distance, [x, y])
I receive:
Error using sym/max (line 97)
Input arguments must be convertible to floating-point numbers.
Error in simulate_cell_clover (line 14)
solx = solve(x == y, max(abs(x),abs(y)) == wall_distance, [x, y])
I can solve the equation by myself (to build a function), but I think it will be wiser to use already build function. Someone knows how can I overcome this problem?
Best Regards, Eli

Risposte (1)

John D'Errico
John D'Errico il 15 Apr 2016
Why would you use symbolic tools to solve this problem? Sorry, but that is a bit silly, using a Mack truck to carry a pea to Boston. A symbolic solution, IF you managed to make it work, would still be slow. That is the nature of symbolic tools.
You have a ray emanating form the origin. You apparently wish to find the intersection of that ray with the edges of a square box.
Algorithm 1:
Use linprog (or any linear programming tool) to find the farthest point along the line, subject to the constraints that the point falls inside all of the edges of the square. This is easy enough to write, and efficient to execute. Of course, it requires a linear programming tool.
Algorithm 2:
Just find the intersection of the ray with each line segment of the box, as a line, so this is just finding the intersection of two lines in two dimensions. If that intersection point falls inside the boundaries of the line segment for the corresponding edge, you are done. Repeat for each edge of the box. This is just a simple loop.
Sometimes a loop is the right solution. Or use linprog.
  1 Commento
Eli Borodach
Eli Borodach il 17 Apr 2016
I am sorry for my improper English but what do you mean in the term symbolic? And why your solution will run quicker than mine?

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by