Why does my code only create points instead of lines?

  • Context: Mathematica 
  • Thread starter Thread starter button_ger
  • Start date Start date
  • Tags Tags
    Lines Mathematica
Click For Summary
SUMMARY

The discussion centers on a coding issue in Mathematica where the user, Jens, initially attempts to create lines from the solutions of equations representing a circle and a line but only generates points. The solution involved modifying the code to correctly replace the points with line segments using the replacement function. The final working code utilizes the syntax Graphics[Line[sol]] to display the lines, effectively resolving the issue.

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of geometric equations, specifically circles and lines
  • Knowledge of the NSolve function in Mathematica
  • Basic concepts of graphical representation in Mathematica
NEXT STEPS
  • Explore advanced features of NSolve in Mathematica
  • Learn about graphical functions in Mathematica, such as Graphics and Line
  • Investigate the use of replacement rules in Mathematica
  • Study the implications of using Table for generating multiple solutions
USEFUL FOR

Mathematica users, mathematicians, and programmers interested in graphical representations of mathematical equations and troubleshooting code related to geometric visualizations.

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 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 14 ·
Replies
14
Views
4K
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 52 ·
2
Replies
52
Views
13K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K