Mathematica Why does my code only create points instead of lines?

  • Thread starter Thread starter button_ger
  • Start date Start date
  • Tags Tags
    Lines Mathematica
AI Thread Summary
The original code was intended to create lines based on the solutions of an equation involving a circle and a line but only produced points. The issue was resolved by modifying the way the solutions were handled in the code, specifically by correctly formatting the output for the `Graphics` function. The revised code uses a replacement function to generate the lines from the solutions, allowing for proper visualization. There is some confusion regarding the effectiveness of the new code, as one user reported it still failed for them. The discussion highlights the importance of correctly structuring the output for graphical representation in programming.
button_ger
Messages
10
Reaction score
0
Hy Guys

I want to create some lines. That lines should be created by the solution of an equation. This equation has in my limits 1 or 2 solutions. The first euation is a circle.
The second is a line.

lineslope, radius, lineshift1, lineshift2 is defined before.

Code:
sol = Table[
  NSolve[{radius^2 == (x - radius)^2 + (y - radius)^2, 
    y == lineslope*x + i}, {x, y}]
  , {i, lineshift1, lineshift2, 20}]
Show[Graphics[Line[{{x, y}, {x, y}}]] /. sol]

This code only creates only points? Why? can anybody help me?

Greets
Jens
 
Physics news on Phys.org
I have solved the problem.

I changed ...
PHP:
sol = Table[
  NSolve[{radius^2 == (x - radius)^2 + (y - radius)^2, 
    y == lineslope*x + i}, {x, y}]
  , {i, lineshift1, lineshift2, 20}]
Show[Graphics[Line[{{x, y}, {x, y}}]] /. sol]

in...

PHP:
sol = Table[
  NSolve[{x,y}/.{radius^2 == (x - radius)^2 + (y - radius)^2, 
    y == lineslope*x + i}, {x, y}]
  , {i, lineshift1, lineshift2, 20}]
Show[Graphics[Line[sol]]]

This did it. But how is the replacing function working right to replace the Line[{{x,y},{x2,y2}}] correctly?
 
Last edited:
What you probably wanted in your original equation was:
Graphics[Line[{x, y} /. sol]]

I don't know how your new code is working for you, it failed for me.
 

Similar threads

Replies
1
Views
2K
Replies
6
Views
4K
Replies
3
Views
2K
Replies
4
Views
5K
Replies
52
Views
12K
Replies
4
Views
3K
Replies
1
Views
5K
Replies
5
Views
2K
Back
Top