tomleslie

13821 Reputation

20 Badges

14 years, 301 days

MaplePrimes Activity


These are replies submitted by tomleslie

@AHSAN 

no idea what you want - maybe the attached,which does dra the relevant line on the relevant surface.

 f := transform((X, Y) -> [X, 0.5, Y]):

is used to transrom a 2D plot to a 3D plot - see the help at plottools/transform.

I replied to the question at

https://www.mapleprimes.com/questions/235239-Help-Regarding-Graph-Style-And-Comparesion

oddPlot2.mw

@AHSAN 

see the attached, whihc for some reason won't display inline here

plots_3.mw

You can browse books on Maple here https://www.maplesoft.com/books/index.aspx

depends which documentation you are using!

I may be a bit old-fashioned, but I think that for learning Maple from scratch, the (pdf) manuals available here

https://www.maplesoft.com/documentation_center/

are a better bet than simply using the built-in help.

These manuals are available in worksheet format in the built-in help, which I don't find as convenient as the pdf versions

@AHSAN 

now the analytical and numerical solutions agree and all graphs display- see the attached.

restart

ode := diff(theta(y), y, y)+Br*((-3*We*(y+1+(1/2)*x^2)*((9*(1+(1/2)*x^2)^2+9*y^2)*(k*(1+(1/2)*x^2)+2*Q-1-(1/2)*x^2)^3/(4*(1+(1/2)*x^2)^7)+3*y*(k+1)*(k*(1+(1/2)*x^2)+2*Q-1-(1/2)*x^2)^2/(1+(1/2)*x^2)^5+3*(k+1)^2*(k*(1+(1/2)*x^2)+2*Q-1-(1/2)*x^2)/(2*(1+(1/2)*x^2)^3)-(-120*lambda*(1+(1/2)*x^2)^4+(63*k^2-36*k+63)*(k-1)*(1+(1/2)*x^2)^3+288*Q*(k^2-(11/8)*k+1)*(1+(1/2)*x^2)^2+486*Q^2*(k-1)*(1+(1/2)*x^2)+324*Q^3)/(15*(1+(1/2)*x^2)^5))/(16*(1+(1/2)*x^2)^2)-3*We*(y-1-(1/2)*x^2)*((9*(1+(1/2)*x^2)^2+9*y^2)*(k*(1+(1/2)*x^2)+2*Q-1-(1/2)*x^2)^3/(4*(1+(1/2)*x^2)^7)+3*y*(k+1)*(k*(1+(1/2)*x^2)+2*Q-1-(1/2)*x^2)^2/(1+(1/2)*x^2)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+(1/2)*x^2)+2*Q-1-(1/2)*x^2)^2/(1+(1/2)*x^2)^5+3*(k+1)^2*(k*(1+(1/2)*x^2)+2*Q-1-(1/2)*x^2)/(2*(1+(1/2)*x^2)^3)-(-120*lambda*(1+(1/2)*x^2)^4+(63*k^2-36*k+63)*(k-1)*(1+(1/2)*x^2)^3+288*Q*(k^2-(11/8)*k+1)*(1+(1/2)*x^2)^2+486*Q^2*(k-1)*(1+(1/2)*x^2)+324*Q^3)/(15*(1+(1/2)*x^2)^5))/(16*(1+(1/2)*x^2)^2)-3*We*(y-1-(1/2)*x^2)*(y+1+(1/2)*x^2)*(9*y*(k*(1+(1/2)*x^2)+2*Q-1-(1/2)*x^2)^3/(2*(1+(1/2)*x^2)^7)+(3*(k+1))*(k*(1+(1/2)*x^2)+2*Q-1-(1/2)*x^2)^2/(1+(1/2)*x^2)^5)/(16*(1+(1/2)*x^2)^2)+(-3*y*(k*(1+(1/2)*x^2)+2*Q-1-(1/2)*x^2)/(1+(1/2)*x^2)^2-k-1)/(x^2+2))^4) = 0

bc := theta(-1-(1/2)*x^2) = 0, theta(1+(1/2)*x^2) = 1

Q__vals := [.5617, .4392, .2564, .1645, 0.659e-1]

`λ__vals` := [0.96e-2, 0.10e-2, 0.93e-2, 0.75e-2, 0.31e-2]; k__vals := [.1, .3, .5, .7, .9]

We__vals := [.1, .3, .5, .7, .9]

colors := [black, red, blue, green, orange, cyan, purple, yellow, navy]; for j to numelems(k__vals) do sol := dsolve(eval([ode, bc], [k = k__vals[j], We = .1, Br = .3, x = 0, Q = Q__vals[j], lambda = `λ__vals`[j]]), numeric); pltn[j] := plots:-odeplot(sol, [y, theta(y)], y = 0 .. 1, axes = boxed, color = colors[j]) end do; plots:-display([seq(pltn[j], j = 1 .. 5)], title = "Numerical Solution")

 

NULL

Analytical_sol := -(3*y+3+3*x^2*(1/2))*((-2/3+(-(5/12)*k^2+(1/6)*k-5/12)*Br)*(1+(1/2)*x^2)^5-Br*((-(1/12)*k^2+(1/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1+(1/2)*x^2)*(y-1-(1/2)*x^2)/(20*(1+(1/2)*x^2)^12)

NULL

for j to numelems(k__vals) do sol[j] := eval(Analytical_sol, [k = k__vals[j], We = .1, Br = .3, x = 0, Q = Q__vals[j], lambda = `λ__vals`[j]]); plta[j] := plot(sol[j], y = 0 .. 1, axes = boxed, color = colors[j], linestyle = dash, thickness = 6) end do; plots:-display([seq(plta[j], j = 1 .. numelems(k__vals))], title = "Analytical Solution"); plots:-display([seq(plots:-display([pltn[j], plta[j]]), j = 1 .. numelems(k__vals))], title = "Numerical and Analytical Solutions")

 

 

``

 

Download plots_2.mw

@zenterix 

The term "garbage" may have been a bit strong - but I was having a bad day.

However you did state

plot the arrow individually; it works. Plot the trail individually; it works

which for the code you posted,  Animation_Test.mw, is simply untrue. The "arrow" part works, but the "trail" part generates the error

Error, (in plots:-pointplot3d) points are not in the correct format

This tells me that you have not even tested the code which you posted. This fills me with great joy, because now I know I cannot trust any of your code and have to check it line by line.

Furthermore, the code overall is (I think) unnecessarily complicated. You don't need any "procedures", just correct use of the display() command - see the attached

When you post code here using the big green up-arrow in the Mapleprimes toolbar you have a choice between "Insert link" and "Insert contents". Using the latter means that code will be displayed (as in the attached) and animations will play. This is generally preferred behaviour - it gives potential responders a quick idea of what they might be getting into without downloading your worksheet and firing up Maple

  restart:
  with(plots):
  r:= rand(1 .. 10):
  testData:= Matrix( [ seq( [r(), r(), r()],
                            i = 1 .. 20
                          )
                     ]
                   ):
#
# Set the length of the "trail" and display the
# results as an animation
#
  lenTrail:= 5:
  display
  ( [ seq
      ( display
        ( [ plottools:-sphere( [5,5,5],
                               2,
                               color=black,
                               transparency=0.8
                             ),
            arrow( testData[j,..],
                   color=red
                 ),
            pointplot3d( testData[max([1, j-lenTrail])..j,...],
                         color=blue,
                         connect=true,
                         thickness=4
                       )
          ]
        ),
        j=1..op([1,1], testData)
      )
    ],
    insequence=true
  );

 

 

Download toyAnim3.mw

 

@zenterix 

The most glaring of which is that you define

testData1 := Matrix([seq([r(), r(), r()], i = 1 .. 20)]);
testData2 := Matrix([seq([r(), r(), r()], i = 1 .. 20)]);

and then you attempt to execute the command

trail := [seq(m1(testData, t, windowSize, blue), t = [seq(1 .. 20)])]

when testData is not defined!!!!

I tend to agree witth acer! Every time you get an answer, you change the question.

Since the latest worksheet you posted is pretty much garbage, I have to make some wild guesses about your intent. It is highly likely that some of my guesses are incorrect, but at least the attached executes (and looks vaguely plausible?)

r := rand(1 .. 10)

testData1 := Matrix([seq([r(), r(), r()], i = 1 .. 20)])

testData2 := Matrix([seq([r(), r(), r()], i = 1 .. 20)])

m2 := proc (q1, t, arrowColor) return plots:-arrow([[0, 0, 0], q1[t]], color = arrowColor) end proc

m1 := proc (q1, t, windowSize) if t <= windowSize then return plots:-pointplot3d(q1[1 .. t, () .. ()], connect = true, color = black, thickness = 4) end if; return plots:-pointplot3d(q1[t-windowSize+1 .. t, () .. ()], connect = true, color = black, thickness = 4) end proc

times := seq(1 .. 20)

windowSize := 10

Generate animation data for an arrow

arrow := [seq(m2(testData1, t, red), t = times)]

Generate animation data for a "trail" of the last windowSize positions of the arrow

trail := [seq(m1(testData1, t, windowSize, blue), t = [seq(1 .. 20)])]
Plot just the arrow animation

plots:-display(arrow, insequence = true)

 

Plot just the trail animation

plots:-display(trail, insequence = true)

 

Attempt to plot both together. The attempt below plots them sequentially, but I want to plot them at the same time.

plots:-display([seq(plots:-display([arrow[j], trail[j]]), j = 1 .. numelems(trail))], insequence = true)

 

 

NULL

NULL

Download animTest.mw

@zenterix 

is a poor choice! In general there is nothing you can do with a plots:-animate() command that is impossible to do with a plots:-display() command using the option insequence=true. It is however a lot easier to export the data for the latter since they are simple matrices.

It is pretty trivial to extend my previous worksheet to  have

  1. multiple curves in the same animation
  2. something which mimics the "trace" option in an animate command
  3. something which mimics the "background" option in an animate command

whilst still just exporting and importing matrices. See the attached

  restart;
  with(plots):
  with(plottools):
  odesys:= [ diff(x(t),t) = x(t) - x(t)*y(t),
             diff(y(t),t) = x(t)*y(t) - y(t)
           ] :
  tv:= Array([seq( j, j=0..10,0.1)]):
  ics:= [x(0)=k1, y(0)=k2]:
#
# Solve odesys, for different initial conditions
# and extract the matrix which contains the results
# to be plotted
#
# 'sol' is a list of such matrices
#  
  sol:= [ seq( [ dsolve( [odesys[], eval(ics, [k1=j, k2=1])[]],
                          numeric,
                          output=tv
                       )[2,1][..,2..3],
                 dsolve( [odesys[], eval(ics, [k1=j, k2=2])[]],
                          numeric,
                          output=tv
                       )[2,1][..,2..3]
                ][],
               j=1.5..2.5, 0.1
             )
        ]:
#
# Display the results as an animation
#
  plt1:=circle([1,1], 1, color=black, thickness=4):
  display
  ( [ seq
      ( display
        ( [ plt1,
            listplot( sol[j], color=red),
            seq( listplot( sol[k], color=blue), k=2..j+1,2)
          ]
        ),
        j=1..numelems(sol),2
      )
    ],
    insequence=true
  );
#
# Export the list of solution matrices
#
  ExportMatrix( "C:/Users/TomLeslie/Desktop/test.mat", [op(1,plt1), sol[]], target=Matlab);

 

39267

(1)

  restart;
  with(plots):
#
# Import the list of solution matrices which was generated above
#
  ans:=[ImportMatrix( "C:/Users/TomLeslie/Desktop/test.mat", output=matrices)]:
#
# Display the results as an animation
#
  display
  ( [ seq
      ( display
        ( [ listplot( ans[1], color=black, thickness=4),
            listplot( ans[j], color=red),
            seq( listplot( ans[k], color=blue), k=3..j+1,2)
          ]
        ),
        j=2..numelems(ans),2
      )
    ],
    insequence=true
  );
  

23

 

 

 

 

 

 

Download toyAnim2.mw

@JAMET 

You can watch it working in my previous post.

I think what you mean is that you have edited it for some reason, and the edited version does not work.

Post the non-functional worksheet on this site using the big green up-arrow in the Mapleprimes toolbar

@nm 

what criteria Maple adopts for this choice. You can always workaround it by supplying the 'useint' option - whihc is just the equivalent of saying "try really hard to solve any integrals appearing in the solution"

If you still get an unevaluated integral when using this option, then you can be sure that Maple cannot perform the integration

  restart;
  ode:=diff(y(x),x)=(b*y(x)+sqrt(y(x)^2+b^2-1) )/(b^2-1);
  dsolve(ode, useint);

diff(y(x), x) = (b*y(x)+(y(x)^2+b^2-1)^(1/2))/(b^2-1)

 

x+ln(y(x)+(y(x)^2+b^2-1)^(1/2))*b^2/((b+1)*(b-1))-ln(y(x)+(y(x)^2+b^2-1)^(1/2))/((b+1)*(b-1))+(1/2)*b^4*ln((2*b^2-2*y(x)-2+2*(b^2)^(1/2)*(y(x)^2+b^2-1)^(1/2))/(y(x)+1))/((b+1)*(b-1)*(b^2)^(1/2))-(1/2)*b^2*ln((2*b^2-2*y(x)-2+2*(b^2)^(1/2)*(y(x)^2+b^2-1)^(1/2))/(y(x)+1))/((b+1)*(b-1)*(b^2)^(1/2))-(1/2)*b^4*ln((2*b^2+2*y(x)-2+2*(b^2)^(1/2)*(y(x)^2+b^2-1)^(1/2))/(y(x)-1))/((b+1)*(b-1)*(b^2)^(1/2))+(1/2)*b^2*ln((2*b^2+2*y(x)-2+2*(b^2)^(1/2)*(y(x)^2+b^2-1)^(1/2))/(y(x)-1))/((b+1)*(b-1)*(b^2)^(1/2))-(1/2)*b^3*ln(y(x)-1)/(b^2-1)+(1/2)*b*ln(y(x)-1)/(b^2-1)-(1/2)*b^3*ln(y(x)+1)/(b^2-1)+(1/2)*b*ln(y(x)+1)/(b^2-1)+_C1 = 0

(1)

 

Download odeVal2.mw

@JAMET 

what you mean by the "the q on p jumps". I see two possibilities

  1. I explained in my previous post that the first execution group generated the reflectied ellipse 'q' from 'p' using the geometry:-reflection(q, p, l1) command. This sometimes gave the "wrong" answer, and I didn't know why. So this animation iss really screwed up. (Which is why I provided the second execution group, where the necessary reflection was performed using the plottools:-reflect() command.) I subsequently discovered, that if I forced "floating-point" rather than "exact" calculations, the problem with the geometry:-reflection(q, p, l1) disappeared!!?? This is shown in the attached, in whihc both animations now work correctly
  2. There is another possible "stutter" in these animations, depending on whether you are running them for a single cycle, or continuously looping. If one generates frames, using seq(Fig(2*Pi*i/nFig), i = 0.0 .. nFig), then the starting frame and the ending frame are the same - which "looks right" for a single cycle. However if the animation is continuously looping, then this means that one frame occurs twice, because Fig(0) and Fig(2*Pi) produce the same result. You can make the continuous-looping behaviour "look better" by changing the seq() command to seq(Fig(2*Pi*i/nFig), i = 0.0 .. nFig-1.0) - although this means that on a single-cycle animation, you won't (quite) finiish where you started.

Both of the above changes have been made in the attached. As always the animations *look* better in a real Maple worksheet than they do on this site

  restart:
  with(geometry):
  _EnvHorizontalName := 'x':
  _EnvVerticalName := 'y':
  a := 7:
  b := 3:
  ellipse(p, x^2/a^2 + y^2/b^2 - 1, [x, y]):
  Fig := proc(t)
              local M, l1, q, m, c;
              global a, b, p;
              point(M, a*cos(t), b*sin(t));
              if   VerticalCoord(M)=0
              then line(l1, x=HorizontalCoord(M));
              else m:=eval[recurse]( rhs
                                     ( isolate
                                       ( diff
                                         ( eval
                                           ( Equation(p),
                                             y=y(x)
                                           ),
                                           x
                                         ),
                                         diff(y(x),x)
                                       )
                                     ),
                                     [ y(x)=y,
                                       x=HorizontalCoord(M),
                                       y=VerticalCoord(M)
                                     ]
                                   );
                   c:=VerticalCoord(M)-m*HorizontalCoord(M);
                   line(l1, y=m*x+c);
              fi;
              reflection(q, p, l1);
              draw( [ p(color = blue),
                      q(color = blue),
                      l1(color = black),
                      M(color = red, symbol = solidcircle, symbolsize = 16)
                    ],
                    axes = normal,
                    scaling = constrained);
          end proc:
#
# Change nFig to type float
#
   nFig := 60.0:
#
# Make sure loop index is a float, and change end point
# on loop to nFig-1.0
#
   Figs := seq(Fig(2*Pi*i/nFig), i = 0.0 .. nFig-1.0):
   plots:-display(Figs, insequence = true);

 

 

  restart:
  with(geometry):
  _EnvHorizontalName := 'x':
  _EnvVerticalName := 'y':
  a := 7:
  b := 3:
  ellipse(p, x^2/a^2 + y^2/b^2 - 1, [x, y]):
  Fig := proc(t)
              local M, l1, q, m, c, plt1;
              global a, b, p;
              point(M, a*cos(t), b*sin(t));
              if   VerticalCoord(M)=0
              then line(l1, x=HorizontalCoord(M));
              else m:=eval[recurse]( rhs
                                     ( isolate
                                       ( diff
                                         ( eval
                                           ( Equation(p),
                                             y=y(x)
                                           ),
                                           x
                                         ),
                                         diff(y(x),x)
                                       )
                                     ),
                                     [ y(x)=y,
                                       x=HorizontalCoord(M),
                                       y=VerticalCoord(M)
                                     ]
                                   );
                   c:=VerticalCoord(M)-m*HorizontalCoord(M);
                   line(l1, y=m*x+c);
              fi;
              plt1:= draw( [ p(color = blue),
                             l1(color = black),
                             M(color = red, symbol = solidcircle, symbolsize = 16)
                           ],
                           axes = normal,
                           scaling = constrained
                         );
              plots:-display( [ plt1,
                                plottools:-reflect
                                           ( plt1,
                                             [ HorizontalCoord(M), VerticalCoord(M)]
                                           )
                              ],
                              axes = normal,
                              scaling = constrained,
                              view=[-22..22, -22..22]
                            );
          end proc:
#
# Change nFig to type float
#
   nFig := 60.0:
#
# Make sure loop index is a float, and change end point
# on loop to nFig-1.0
#
   Figs := seq(Fig(2*Pi*i/nFig), i = 0.0 .. nFig-1.0):
   plots:-display(Figs, insequence = true);

 

 

Download Tangents2.mw

There are a couple of issues with the Student:-Calculus1:-Tangent() command

  1. It doesn't handle the case where the tangent line is vertical, ie has infinite gradient. For your example, this occurs whenever the y-coordinate of the ellipse is zero, so I have included a simple trap for such a situation in the attached
  2. Since it generates a tangent specified at a point defined only by its x-value it has problems with shapes such as an ellipse, where for a given x-value, there are two possible tangency points. For this reason in the attached, I wrote a "first principles" tangent line calculator, and discarded the Student:-Calculus1:-Tangent() command completely.
  3. The result of this is shown in the first execution group of the attached

If you examine the animation of the first execution group in the attached, it is obvious that for some tangent lines, the geometry:-reflection() command is failing - I have no idea why! It seems to occur for fairly random tangent lines, and I haven't been able to come up with a plausible explanation.

The second execution group in the attached produces the second ellipse, by using the plottools:-reflect() command and this always seems to work.

  restart:
  with(geometry):
  _EnvHorizontalName := 'x':
  _EnvVerticalName := 'y':
  a := 7:
  b := 3:
  ellipse(p, x^2/a^2 + y^2/b^2 - 1, [x, y]):
  Fig := proc(t)
              local M, l1, q, m, c;
              global a, b, p;
              point(M, a*cos(t), b*sin(t));
              if   VerticalCoord(M)=0
              then line(l1, x=HorizontalCoord(M));
              else m:=eval[recurse]( rhs
                                     ( isolate
                                       ( diff
                                         ( eval
                                           ( Equation(p),
                                             y=y(x)
                                           ),
                                           x
                                         ),
                                         diff(y(x),x)
                                       )
                                     ),
                                     [ y(x)=y,
                                       x=HorizontalCoord(M),
                                       y=VerticalCoord(M)
                                     ]
                                   );
                   c:=VerticalCoord(M)-m*HorizontalCoord(M);
                   line(l1, y=m*x+c);
              fi;
              reflection(q, p, l1);
              draw( [ p(color = blue),
                      q(color = blue),
                      l1(color = black),
                      M(color = red, symbol = solidcircle, symbolsize = 16)
                    ],
                    axes = normal,
                    scaling = constrained);
          end proc:
   nFig := 60:
   Figs := seq(Fig(2*Pi*i/nFig), i = 0 .. nFig):
   plots:-display(Figs, insequence = true);

 

  restart:
  with(geometry):
  _EnvHorizontalName := 'x':
  _EnvVerticalName := 'y':
  a := 7:
  b := 3:
  ellipse(p, x^2/a^2 + y^2/b^2 - 1, [x, y]):
  Fig := proc(t)
              local M, l1, q, m, c, plt1;
              global a, b, p;
              point(M, a*cos(t), b*sin(t));
              if   VerticalCoord(M)=0
              then line(l1, x=HorizontalCoord(M));
              else m:=eval[recurse]( rhs
                                     ( isolate
                                       ( diff
                                         ( eval
                                           ( Equation(p),
                                             y=y(x)
                                           ),
                                           x
                                         ),
                                         diff(y(x),x)
                                       )
                                     ),
                                     [ y(x)=y,
                                       x=HorizontalCoord(M),
                                       y=VerticalCoord(M)
                                     ]
                                   );
                   c:=VerticalCoord(M)-m*HorizontalCoord(M);
                   line(l1, y=m*x+c);
              fi;
              plt1:= draw( [ p(color = blue),
                             l1(color = black),
                             M(color = red, symbol = solidcircle, symbolsize = 16)
                           ],
                           axes = normal,
                           scaling = constrained
                         );
              plots:-display( [ plt1,
                                plottools:-reflect
                                           ( plt1,
                                             [ HorizontalCoord(M), VerticalCoord(M)]
                                           )
                              ],
                              axes = normal,
                              scaling = constrained,
                              view=[-22..22, -22..22]
                            );
          end proc:
   nFig := 60:
   Figs := seq(Fig(2*Pi*i/nFig), i = 0 .. nFig):
   plots:-display(Figs, insequence = true);

 

 

Download Tangents.mw

 

use the big green up-arrow in the Mapleprimes toolbar to upload the worksheet which generates this error

reading the help - because you will often find the answer much faster than asking questions on Mapleprimes. You are getting the error message

Error, (in geometry:-tangentpc) wrong type of arguments

The first line of teh help for the geometry:-tangentpc() command states (emphasis added)

find the tangent of a point on a circle with respect to that circle

and you want the tangent to an ellipse!

Fixed in the attached

  restart:
  with(geometry):
  _EnvHorizontalName := 'x':
  _EnvVerticalName := 'y':
  a := 7:
  b := 3:
  t := (2*Pi)/3:
  ellipse(p, x^2/a^2 + y^2/b^2 - 1, [x, y]):
  point(P, a*cos(t), b*sin(t)):
  rotation(q, p, t, 'clockwise', P):
  line( l1,
        y=Student[Calculus1]:-Tangent( solve( Equation(p), y)[1],
                                       x=HorizontalCoord(P)
                                     )
      );
  draw( [ p(color = blue),
          q(color = blue),
          l1(color=black),
          P(color=red, symbol=solidcircle, symbolsize=16)
        ],
        axes = normal,
        scaling = constrained
      );

l1

 

 

 

Download aTangent.mw

Maple has ywo interfaces for entering code - known as 1D-input mode and 2D-input mode. When you make the comment

Why is it when the text is in black and not in red that the syntax doesnt work?

you are actually asking

Why does code written using 1D-input mode work and that written using 2D_input mode doesn't?

In your particular case, it is fairly trivial. 2D-Input mode does not support the local declaration in the function definition. If you remove this local definition from the 2D-input code (as I have done in the attached), then you will get a (spurious) warning message, but the code will execute.

I observe from your original post that you are trying to replicate examples from a textbook. These examples appear to be written using 1D-input mode - maybe you should use the same?

On this basis I would recommend that (from the toolbar menus) you set

Tools->Options->Display->Input Display to Maple Notation
Tools->Options->Display->Output Display to 2D Math Notation
Tools->Options->Interface->Default format for new worksheets to Worksheet

and then click "Apply Globally". At least then you will be replicating your textbook input more accurately

  restart;
  with(Student:-VectorCalculus):
  BasisFormat(false):
  toEq:= pl-> local j;
              seq( `if`( type(pl[j], symbol),
                         NULL,
                         syms[j]=pl[j]
                       ),
                       j=1..3
                 ):
  S:=Vector( <2,theta,phi>, coords=spherical);
  A:=simplify( MapToBasis( <1,1,sqrt(2)>, spherical )):
  B:=simplify( MapToBasis( <sqrt(2),sqrt(2),0>, spherical )):
  C:=simplify( MapToBasis( <2,0,0>, spherical )):
  TP1:=simplify( TangentPlane( S, theta=A[2], phi=A[3]));
  TP2:=simplify( TangentPlane( S, theta=B[2], phi=B[3]));
  TP3:=simplify( TangentPlane( S, theta=C[2], phi=C[3]));
  syms:= [x,y,z]:
  toEq(TP1);
  toEq(TP2);
  toEq(TP3);

Vector(3, {(1) = 2, (2) = theta, (3) = phi})

 

Vector(3, {(1) = x, (2) = y, (3) = -(1/2)*sqrt(2)*(x-4+y)})

 

Vector(3, {(1) = x, (2) = -x+2*sqrt(2), (3) = z})

 

Vector[column](%id = 36893488147955752580)

 

z = -(1/2)*2^(1/2)*(x-4+y)

 

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

 

x = 2

(1)

restart
with(Student:-VectorCalculus)
BasisFormat(false)

toEq := proc (pl) options operator, arrow; seq(`if`(type(pl[j], symbol), NULL, syms[j] = pl[j]), j = 1 .. 3) end proc

S := Vector(`<,>`(2, theta, phi), coords = spherical)

A := simplify(MapToBasis(`<,>`(1, 1, sqrt(2)), spherical))

B := simplify(MapToBasis(`<,>`(sqrt(2), sqrt(2), 0), spherical))

C := simplify(MapToBasis(`<,>`(2, 0, 0), spherical))

TP1 := simplify(TangentPlane(S, theta = A[2], phi = A[3]))

TP2 := simplify(TangentPlane(S, theta = B[2], phi = B[3]))

TP3 := simplify(TangentPlane(S, theta = C[2], phi = C[3]))

syms := [x, y, z]

toEq(TP1)

toEq(TP2)
toEq(TP3)

Warning, (in toEq) `j` is implicitly declared local

 

Vector(3, {(1) = 2, (2) = theta, (3) = phi})

 

Vector(3, {(1) = x, (2) = y, (3) = -(1/2)*sqrt(2)*(x-4+y)})

 

Vector(3, {(1) = x, (2) = -x+2*sqrt(2), (3) = z})

 

Vector[column](%id = 36893488147980818780)

 

z = -(1/2)*2^(1/2)*(x-4+y)

 

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

 

x = 2

(2)

``

Download tanplanes3.mw


 

you will find the attached easier to comprehend - I have changed some variable names, added a few commands and comments to the sheet given by rlopez.

A few further comments.

  1. If you think in spherical coordinates, ie < r, theta, phi>, then it *ought* to be fairly obvious, that <2, theta, phi> defines a spherical surface, with radius 2
  2. If one uses the command A:=MapToBasis( <1,1,sqrt(2)>, spherical ), then the  output is just the same point except in spherical coordinates
  3. Notice that values of 'theta' and 'phi' are given by the second and third entries in the above, so that the command TP1:=simplify( TangentPlane( S, theta=A[2], phi=A[3])), where 'S' is a sphere of radius 2, will return the tangent plane at the point given by the spherical coordinates  <2, A[2], A[3]>.
  4. You may find the definition of the tangent planes vectorially, to be slightly weird. You just have to realise that (in cartesian coordinates) any plane has two "free" coordinates: the third coordinate is specified in terms of these free coordinates. In the attached I have "extracted" equations for the planes on this basis.
  5. My first attempt at solving this problem was actually to use the VectorCalculus() package, but with cartesian coordinates. Unfortunately this gave the same division-by-zero errors, which you had already experienced. It didn't ocur to me to use this package with spherical coordinates :-(   which is why you got the two solutions I posted earlier

  restart;
  with(Student:-VectorCalculus):
  BasisFormat(false):
#
# Define the surface in spherical coordinates as a way of
# avoiding the division-by-zero errors one gets in Cartesian
# coordinates.
#
  S:=Vector( <2,theta,phi>, coords=spherical);
#
# Convert the user-specified points to spherical from
# Cartesian coordinates:
#
  A:=simplify( MapToBasis( <1,1,sqrt(2)>, spherical )):
  B:=simplify( MapToBasis( <sqrt(2),sqrt(2),0>, spherical )):
  C:=simplify( MapToBasis( <2,0,0>, spherical )):
#
# The tangent planes are given parametrically (parametric
# expressions are stacked in a vector) by the following commands:
#
  TP1:=simplify( TangentPlane( S, theta=A[2], phi=A[3]));
  TP2:=simplify( TangentPlane( S, theta=B[2], phi=B[3]));
  TP3:=simplify( TangentPlane( S, theta=C[2], phi=C[3]));
#
# Convert above planes to "simple" equations
#
  syms:= [x,y,z]:
  toEq:= pl-> local j;
              seq( `if`( type(pl[j], symbol),
                         NULL,
                         syms[j]=pl[j]
                       ),
                       j=1..3
                 ):
  toEq(TP1);
  toEq(TP2);
  toEq(TP3)

Vector(3, {(1) = 2, (2) = theta, (3) = phi})

 

Vector(3, {(1) = x, (2) = y, (3) = -(1/2)*sqrt(2)*(x-4+y)})

 

Vector(3, {(1) = x, (2) = -x+2*sqrt(2), (3) = z})

 

Vector[column](%id = 36893488147946245764)

 

z = -(1/2)*2^(1/2)*(x-4+y)

 

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

 

x = 2

(1)

 


 

Download tanPlanes2.mw

 

First 8 9 10 11 12 13 14 Last Page 10 of 207