Ronan

1172 Reputation

14 Badges

12 years, 186 days
East Grinstead, United Kingdom

MaplePrimes Activity


These are answers submitted by Ronan

I came across this approach a couple of years ago for testing if a point is inside or oudside a polyogon.

The theory is given here Topology, Winding Numbers and Signed Area | Algebraic Calculus One | Wild Egg - YouTube

Basically you need to setup a garunteed exterior point to test with. Then ckeck is the segment from thr exterior point to the point of interest crosses any edges of the polyogon. The crossing number can be -1, 0, 1.   Sum the crossing numbers for all edges. If 0 then the point is on the outside else non zero means the point is on inside. The can handle non convex polygons.

restart

"This method  of determining inside  or outside is based on Crossing Number . If two edges cross the number  is either 1 or -1 else the number is 0  "

NULL

NULLNULL

Q is a random exterior point . P is the point of interest to check whether inside or outside.

"By summing the Crossing Number of PQ an every edge of the polyogon  inside outside is determined by   S=0 then outside  S<>0 then inside"

with(plots); with(plottools)

NULL

_local(D)

Warning, A new binding for the name `D` has been created. The global instance of this name is still accessible using the :- prefix, :-`D`.  See ?protect for details.

 

``

SignedArea := proc (a::{Vector, list}, b::{Vector, list}, c::{Vector, list, null} := null) local M, A; if c = null then A := (1/2)*a[1]*b[2]-(1/2)*a[2]*b[1] else A := ((1/2)*b[2]-(1/2)*c[2])*a[1]+(-(1/2)*b[1]+(1/2)*c[1])*a[2]+(1/2)*c[2]*b[1]-(1/2)*c[1]*b[2] end if; return A end proc

NULL

"CrossingNumber := proc(A::list, B::list, C::list, E::list)  local s1, s2, s3, s4;        s1 := SignedArea(A,B,C);       s2 := SignedArea(A,B,E);        s3 := SignedArea(C,E,B);        s4 := SignedArea(C,E,A);        if s1 = 0 and s2 = 0 and s3 = 0 and s4 = 0 then            'undefined'         elif 0 <= signum(s1) and signum(s2) <= 0 then            if 0 <= signum(s3) and signum(s4) <= 0 then                -1             end if         elif signum(s1) <= 0 and 0 <= signum(s2) then            if signum(s3) <= 0 and 0 <= signum(s4) then               1             end if         else         0         end if;  end proc:"

NULL

Polygon Vertices

A := [0, 0]; B := [200, 0]; C := [200, 300]; D := [250, 400]; E := [500, 300]; F := [500, 500]; G := [0, 500]

COPS := [A, B, C, D, E, F, G, A]

[[0, 0], [200, 0], [200, 300], [250, 400], [500, 300], [500, 500], [0, 500], [0, 0]]

(1)

Points for checking

K := [275, 365]; L := [105, 100]; M := [400, 400]; RoP := [472.991, 557.13]; Points := [K, L, M]

display(polygon(COPS, colour = yellow), point(Points, color = red, symbol = cross, symbolsize = 50), point([RoP], color = blue, symbol = circle, symbolsize = 25))

 

``

for p to nops(Points) do S := 0; for e to nops(COPS)-1 do S := S+CrossingNumber(COPS[e], COPS[e+1], Points[p], RoP); print(CrossingNumber(COPS[e], COPS[e+1], Points[p], RoP)) end do; if S = 0 then print("S=", S, " point of interest is outside") else print("S=", S, "  point of interest is inside") end if end do

"S=", 0, " point of interest is outside"

(2)

NULL

``

Download Inside_or_Outside.mw

You should read the help on taylor and % as I have used that too
 

restart

NULL

t1 := taylor(sin(x), x = 0, 10)

series(x-(1/6)*x^3+(1/120)*x^5-(1/5040)*x^7+(1/362880)*x^9+O(x^11),x,11)

(1)

t2 := taylor(sin(x)*cos(x), x = 0, 10)

series(x-(2/3)*x^3+(2/15)*x^5-(4/315)*x^7+(2/2835)*x^9+O(x^11),x,11)

(2)

coeff(t1, x, 3)

-1/6

(3)

coeff(t2, x, 3)

-2/3

(4)

`%%`/%

1/4

(5)

NULL

coeff(t1, x, 5)

1/120

(6)

coeff(t2, x, 5)

2/15

(7)

`%%`/%

1/16

(8)

NULL

coeff(t1, x, 7)

-1/5040

(9)

coeff(t2, x, 7)

-4/315

(10)

`%%`/%

1/64

(11)

NULL

coeff(t1, x, 9)

1/362880

(12)

coeff(t2, x, 9)

2/2835

(13)

`%%`/%

1/256

(14)

NULL

The pattern is a geometric series based on 1/4


 

Download taylor-1.mw


 

restart

NULL

A := Vector[row]([a1, a2, a3, a4])

Vector[row](%id = 36893489805968615532)

(1)

B := Vector[row]([b1, b2, b3, b4])

Vector[row](%id = 36893489805968735636)

(2)

M := Matrix(4, 8)

Matrix(%id = 36893489805983850972)

(3)

``

for i to 4 do M[i, 2*i-1] := A[i]; M[i, 2*i] := B[i] end do

b4

(4)

M

Matrix(%id = 36893489805983850972)

(5)

NULL


 

Download Build_Matrix_from_Vectors.mw

This will plot the half circle.


 

restart

NULL

eq := x^2+y^2 = 4

x^2+y^2 = 4

(1)

plots:-implicitplot(eq, x = -2 .. 2, y = 0 .. 2, scaling = constrained)

 

NULL


 

Download Half_Circle.mw

Set e to be local is one way to suppress the warning.

local e
                            

a := e^5;
 


e := 2;
                        

a;
                               32

 

This is not as efficient as the other solutions. It just shows more of the steps involved.
 

restart

with(plots)

NULL

P := [6, -3]

[6, -3]

(1)

line := x+2*y-1

x+2*y-1

(2)

lineperp := 2*x-y+c

2*x-y+c

(3)

NULL

c := solve(eval(lineperp, [x = 6, y = -3]), c)

-15

(4)

lineperp

2*x-y-15

(5)

display(implicitplot([line, lineperp], x = -5 .. 8, y = -8 .. 5), pointplot(P, colour = red), scaling = constrained)

 

Pint := eval([x, y], solve({line, lineperp}))

[31/5, -13/5]

(6)

Focus := P+(P-Pint)

[29/5, -17/5]

(7)

display(implicitplot([line, lineperp], x = 0 .. 10, y = -5 .. 5), pointplot([P, Pint, Focus], colour = [red, green, blue]), scaling = constrained)

 

``

distptl := proc (a, b, c) options operator, arrow; (a*x+b*y+c)/sqrt(a^2+b^2) end proc

proc (a, b, c) options operator, arrow; (a*x+b*y+c)/sqrt(b^2+a^2) end proc

(8)

Parb := (x-Focus[1])^2+(y-Focus[2])^2 = distptl(1, 2, -1)^2

(x-29/5)^2+(y+17/5)^2 = (1/5)*(x+2*y-1)^2

(9)

"(->)"

4*x^2+(-4*y-56)*x+y^2+38*y+225 = 0

(10)

``````

display(implicitplot([Parb, line, lineperp], x = 3 .. 10, y = -6 .. 1, colour = [pink, yellow, purple]), pointplot([P, Pint, Focus], colour = [red, green, blue]), scaling = constrained)

 

NULL


 

Download Parabola_from_vertex_and_line.mw

I deleted my original answer to correct my solution. This is not as efficient as @Rouben Rostamian . It just expands out the steps involved.


 

restart

NULL

f := proc (x) options operator, arrow; (x^3+9*x^2-9*x-1)/(x^4+1) end proc

proc (x) options operator, arrow; (x^3+9*x^2-9*x-1)/(x^4+1) end proc

(1)

fsolve(f(x), x)

-.1010205144

(2)

slopef := unapply(diff(f(x), x), x)

proc (x) options operator, arrow; (3*x^2+18*x-9)/(x^4+1)-4*(x^3+9*x^2-9*x-1)*x^3/(x^4+1)^2 end proc

(3)

sol1 := [solve(slopef(x) = .5, x)]

[.4396034712, 1.545359967, 1.135924545+3.219224078*I, 0.7028667536e-1+.8729569266*I, -.8928416048, -3.504544275, 0.7028667536e-1-.8729569266*I, 1.135924545-3.219224078*I]

(4)

NULL

graphs := plot([f(x), slopef(x)], x = -10 .. 4, colour = [red, blue])

 

Eqline := proc (x, y, m, c) options operator, arrow; m*x+c = y end proc

proc (x, y, m, c) options operator, arrow; m*x+c = y end proc

(5)

P1y := f(sol1[1])

-3.019451886

(6)

m := .5

.5

(7)

line1 := Eqline(sol1[1], P1y, m, c1)

.2198017356+c1 = -3.019451886

(8)

c1 := solve(line1, c1)

-3.239253622

(9)

line1 := Eqline(x, y, m, c1)

.5*x-3.239253622 = y

(10)

NULL

P2y := f(sol1[2])

1.532928834

(11)

``

line2 := Eqline(sol1[2], P2y, m, c2)

.7726799835+c2 = 1.532928834

(12)

c2 := solve(line2, c2)

.7602488505

(13)

line2 := Eqline(x, y, m, c2)

.5*x+.7602488505 = y

(14)

NULL

P3y := f(sol1[5])

8.253465266

(15)

``

line3 := Eqline(sol1[5], P3y, m, c3)

-.4464208024+c3 = 8.253465266

(16)

c3 := solve(line3, c3)

8.699886068

(17)

line3 := Eqline(x, y, m, c3)

.5*x+8.699886068 = y

(18)

NULL

P4y := f(sol1[6])

.6456334552

(19)

``

line4 := Eqline(sol1[6], P4y, m, c4)

-1.752272138+c4 = .6456334552

(20)

c4 := solve(line4, c4)

2.397905593

(21)

line4 := Eqline(x, y, m, c4)

.5*x+2.397905593 = y

(22)

NULL

graphslines := plot([lhs(line1), lhs(line2), lhs(line3), lhs(line4)], x = -10 .. 4)

plots:-display(graphs, graphslines)

 

NULL


 

Download equations_of_4_lines.mw

If you have any questions just ask.

Edit:- Corrected my answer as I missed the 1/(x^4+1)
 

restart

NULL

f := proc (x) options operator, arrow; (x^3+9*x^2-9*x-1)/(x^4+1) end proc

proc (x) options operator, arrow; (x^3+9*x^2-9*x-1)/(x^4+1) end proc

(1)

fsolve(f(x), x)

-.1010205144

(2)

slopef := unapply(diff(f(x), x), x)

proc (x) options operator, arrow; (3*x^2+18*x-9)/(x^4+1)-4*(x^3+9*x^2-9*x-1)*x^3/(x^4+1)^2 end proc

(3)

sol1 := [solve(slopef(x) = .5, x)]

[.4396034712, 1.545359967, 1.135924545+3.219224078*I, 0.7028667536e-1+.8729569266*I, -.8928416048, -3.504544275, 0.7028667536e-1-.8729569266*I, 1.135924545-3.219224078*I]

(4)

NULL

graphs := plot([f(x), slopef(x)], x = -10 .. 4, colour = [red, blue])

 

Eqline := proc (x, y, m, c) options operator, arrow; m*x+c = y end proc

proc (x, y, m, c) options operator, arrow; m*x+c = y end proc

(5)

P1y := f(sol1[1])

-3.019451886

(6)

m := .5

.5

(7)

line1 := Eqline(sol1[1], P1y, m, c1)

.2198017356+c1 = -3.019451886

(8)

c1 := solve(line1, c1)

-3.239253622

(9)

line1 := Eqline(x, y, m, c1)

.5*x-3.239253622 = y

(10)

NULL

P2y := f(sol1[2])

1.532928834

(11)

``

line2 := Eqline(sol1[2], P2y, m, c2)

.7726799835+c2 = 1.532928834

(12)

c2 := solve(line2, c2)

.7602488505

(13)

line2 := Eqline(x, y, m, c2)

.5*x+.7602488505 = y

(14)

NULL

P3y := f(sol1[5])

8.253465266

(15)

``

line3 := Eqline(sol1[5], P3y, m, c3)

-.4464208024+c3 = 8.253465266

(16)

c3 := solve(line3, c3)

8.699886068

(17)

line3 := Eqline(x, y, m, c3)

.5*x+8.699886068 = y

(18)

NULL

P4y := f(sol1[6])

.6456334552

(19)

``

line4 := Eqline(sol1[6], P4y, m, c4)

-1.752272138+c4 = .6456334552

(20)

c4 := solve(line4, c4)

2.397905593

(21)

line4 := Eqline(x, y, m, c4)

.5*x+2.397905593 = y

(22)

NULL

graphslines := plot([lhs(line1), lhs(line2), lhs(line3), lhs(line4)], x = -10 .. 4)

plots:-display(graphs, graphslines)

 

NULL


Download equations_of_4_lines.mw

solve(x^4-x^3-3x^2-x+12,x)

This will give you the vlues of x

if you just want numerical answers.

fsolve(x^4-x^3-3x^2-x+12,x)

Hope this helps

Here are two possible ways. Solve the equation before the variables are assigned. e.g. xb:=1000

You can then assign the variables.

or

Use eval and locally give the variables values.

Note your equation has "ab" eb=ab*yb*db*x but "ab" was not assigned you used "xb" so I changed the equation to that.


 

restart

Eq := eb = xb*yb*db*x

eb = xb*yb*db*x

(1)

sol := solve(Eq, x)

eb/(xb*yb*db)

(2)

xb := 1000

1000

(3)

yb := 2500

2500

(4)

db := 5231

5231

(5)

eb := 521

521

(6)

sol

521/13077500000

(7)

restart

NULL

Eq := eb = xb*yb*db*x

eb = xb*yb*db*x

(8)

sol := solve(Eq, x)

eb/(xb*yb*db)

(9)

eval(sol, [xb = 1000, yb = 2500, db = 5231, eb = 521])

521/13077500000

(10)

NULL


 

Download Maple_prine_solve_ans.mw

 This is a way to add elements to a list. 

op[L] removes the brackets from the list. so you get 3,5,7,-6,4,2 to start with. Then ,i^2, i^3 tags on 1,1. The the [   ] reforms a  list. So after 1st loop you now have L as [3,5,7,-6,4,2,1,1]. and it continues

restart

NULL

NULL

L := [3, 5, 7, -6, 4, 2]

[3, 5, 7, -6, 4, 2]

(1)

for i while i^2 < 100 do L := [op(L), i^2, i^3] end do

[3, 5, 7, -6, 4, 2, 1, 1, 4, 8, 9, 27, 16, 64, 25, 125, 36, 216, 49, 343, 64, 512, 81, 729]

(2)

NULL

``


 

Download Loop_List_Add_to.mw

eq := 2*exp(-2*t) + 4*t = 127:

I am not at Maple PC  at the moment.

But looking at the equation,

we see that this your equation isequivalent to exp(-2t) +2t=63.5

as a first approximation 2t=63.5

so t =31.75

exp(-2x31.75) is going to be very small. i.e 5.9000905*10^-29 (from my TI-68 calculator)

Hope that helps.

 

Look up the " is " command. Using it with the  " if " command works to evasluate you conditions. Plus a few corection to you code as @tomleslie did.

potfeld := (x, y) -> 1/sqrt(y^2 + x^2);
for i to 5 do
    for j to 3 do 
       if is(sqrt(i^2 + j^2) <> 0 and sqrt((i - 2)^2 + j^2) <> 0 and potfeld(i, j) < 3) 
        then 
           P[i, j] := plots:-arrow(<i, j>, <D[1](potfeld)(i, j), D[2](potfeld)(i, j)>); 
            else P[i, j] := plots:-arrow(<i, j>, <0.1, 0.1>); 
      end if; 
    end do;
end do;
Pseq := seq(seq([P[k, l]], k = 1 .. 5), l = 1 .. 3);
plots:-display(Pseq, view = [1 .. 5, 1 .. 3], scaling = constrained);

 

The question you have asked requires a decent bit of study. 

I googled "Transformations to hyperbolic plane in Maple"

There are probably many more. 

Hyperbolic Patterns index page (umn.edu)

Hayter_Hyperbolic_report.pdf (dur.ac.uk)

Geometry of Curves and Surfaces with MAPLE - Vladimir Rovenski - Google Books

This one I did actually do several years ago.

Esher’s Limit Circle IV rendered on the complex upper half-plane | Open System - Ark's blog (arkadiusz-jadczyk.eu)

 

2 3 4 5 6 7 Page 4 of 7