tomleslie

13876 Reputation

20 Badges

15 years, 163 days

MaplePrimes Activity


These are answers submitted by tomleslie

more clearly exactly what you want, The code which you posted executes without error and produces the plot which you asked for - ie 'V_TEV-VP' as a function of 'E' and 'T'.

Apparently this does not ptoduce the plot which you want?? So exactly what do you want to plot? Please don't use terms such as abscissa and ordinate which only really apply to 2D plots, just specify what is the x-variable, what is the y-variable and what is the z-variable in your desired plot

For future reference, please use the big green up-arrow in the Mapleprimes toolbar to upload you actual worksheet - it make life easier for responders.

The code which you posted seems a bit "repetitive" and generally "disorganised". The code below (and in the attachment) is in a more "logical" order and (IMHO) much easier to read. It produces the same plot (see below)

  restart;
#
# Some "parameters". NB the parameter 'a' is
# never used - should it be?
#
  h:= 4: m:= 0.035: g:= h*m:            
  k:= 0.15: a:= 0.25: F_ANR:= 4*m:
  r:= 0.1:
#
# Define a couple of "utility" functions
#
  theFunc:= z-> piecewise
                ( z < 9984, 0,
                  z < 14926, (1008.7*(z-9984)/10000+1400)*(z-9984)/10000,
                  z < 58596, (206.43*(z-14926)/10000+2397)*(z-14926)/10000+938.24,
                  z < 277826, 0.42*z-9267.53,
                  0.45*z-17602.28
                ):
  GewSt:= z-> piecewise( z < 24500, 0,
                         (z-24500)*g
                       ):
#
# Computation of V_TEV
#
  K:= 0.6*E*(1-k-g)*(1+r*(1-k-g))^T:
  V_TEV:= K/0.6*(1 - 0.6*theFunc(K)/K):

#
# Computation of VP
#
  Er:= E+(E-theFunc(E))*r:
  V_P:= ( E-theFunc(E)+GewSt(E)-min( theFunc(E),
                                     GewSt(E),
                                     E*F_ANR
                                   )
        )
        *
        (1+r*(1-theFunc(Er)/E ))^T:

#
# difference between V_TEV and VP
#
  VT:= V_TEV-V_P:
  plot3d( VT,
          E = 0 .. 500000,
          T = 1 .. 15,
          axes = boxed,
          style=surface,
          color=red,
          labels=["E", "T", "VT"],
          labelfont=[times, bold, 12]
        );

which produces

Attachment finCalc.mw

 

 

 

 

The solution for one particular innitial condition is shown in the attached

odeSol.mw

  restart;

  odeSys:= diff(S(t),t)=S__0-a*S(t)-g*S(t)*P(t)-T(t)*S(t)+K*c*P(t)+K*b*F(t)+K__1*F(t)^2,
           diff(P(t),t)=g*S(t)*P(t)-c*P(t)-f*F(t)*P(t),
           diff(F(t),t)=f*P(t)*F(t)-b*F(t)-K*F(t)^2,
           diff(T(t),t)=Q__0-alpha*T(t)-alpha__1*T(t)*S(t);

  bcs:= S(0)=S__10, P(0)=P__10, F(0)=F__10, T(0)=T__10;

  params:=[ S__0=1, Q__0=1, a=0.1, b=0.1, c=0.1, K=0.01,
            f=0.09, g=0.08, alpha__1=0.15, alpha=0.3,
            K__1=0.005, theta=0.099, theta__1=2.433,
            S__10=1, P__10=1, F__10=0.5, T__10=0.5
         ]:
  sol:=dsolve( eval([odeSys, bcs], params), numeric):

  plots:-odeplot( sol,
                  [[t, S(t)], [t, F(t)], [t, P(t)], [t, T(t)]],
                  t=0..100,
                  color=[black, red, blue, green]
                );
        

diff(S(t), t) = S__0-a*S(t)-g*S(t)*P(t)-T(t)*S(t)+K*c*P(t)+K*b*F(t)+K__1*F(t)^2, diff(P(t), t) = g*S(t)*P(t)-c*P(t)-f*F(t)*P(t), diff(F(t), t) = f*F(t)*P(t)-b*F(t)-K*F(t)^2, diff(T(t), t) = Q__0-alpha*T(t)-alpha__1*T(t)*S(t)

S(0) = S__10, P(0) = P__10, F(0) = F__10, T(0) = T__10

 

 

all you have is a lot of "simple" syntax errors. I can only suggest that you read the 'help' for the commands in the geometry package ot carefully.

For your specific exampl,e the syntax-corrected code s shown in the attached.

  restart:
   with(geometry):
#
# When using the geometry() package, it is generally a "good
# idea" to define names for the horizontal and vertical coordinates.
# In MOst appilacations these names will be 'x' and 't respectively
# although Maple will not assume this: so define them explicitlt
#
  _EnvHorizontalName:=x:
  _EnvVerticalName:=y:
#
# OP's original code
#
# triangle(T, [point A(0,0), point B(17,0), point C(9.558823529,2.937497699)]);
#
# So many syntax errors in the abve!!!
#
# Correct code would be
#
  triangle( T,
            [ point(A, [0,0]),
              point(B, [17,0]),
              point(C, [9.558823529,2.937497699])
            ]
          ):
#
# OP's next commands
#
  circumcircle(Elc, T, 'centername' = oo):
  draw([T(color=red), Elc(color=blue)]);
  detail(Elc);

 

GeometryDetail(["name of the object", Elc], ["form of the object", circle2d], ["name of the center", oo], ["coordinates of the center", [8.5000000000, -10.6383062000]], ["radius of the circle", 13.6170319400], ["equation of the circle", -1.0000000000*10^(-7)+x^2+y^2-17.0000000000*x+21.2766124000*y = 0])

(1)

 

Download basicGeom.mw

 

the execution group I have added in the attached

odeplots.mw

using the geometry() package is shown in the attached,

  restart:

  with(geometry):
  _EnvHorizontalName:=x:
  _EnvVerticalName:=y:
#
# there are many ways of defining a triangle:
# eg three points, three lines three side lengths
# or some combination of the above. I'm going to
# assume that you know the corrdinates of the three
# vertices, althugh the code could be modified to
# handle pretty much any sensible definition
#
# Define the vertices
#
  verts:= [ [1, 0],
            [7, 0],
            [2, 2]
          ]:
#
# Define a traingle based on these vertices
#
  triangle( T,
            [ point(A, verts[1]),
              point(B, verts[2]),
              point(C, verts[3])
            ]
          ):
#
# Compute the circulcircle for this triangle.
# Produce its center and its radius
#
  circumcircle(circ, T):
  coordinates( center(circ) );
  radius(circ);
#
# Draw the triangle, its circumcircle, and the center
# of the latter
#
  draw( [ T(color=black),
          circ(color=red),
          center(circ)( symbol=solidcircle,
                        symbolsize=16,
                        color=blue
                       )
       ]
      );

[4, -1/4]

 

(1/16)*145^(1/2)*16^(1/2)

 

 

 

Download circtri.mw

 

 

it is a bad idea to make "unnecessary" assignments. You can access the value to which the variable names in sol[] have been equated by using eval( varName, sol), as in the code below

 

  restart;
  sol := { c[1, 1] = 18.00000000, c[1, 2] = -0., u[1, 1] = -.9000000000,
           u[1, 2] = 0., x[1, 1] = 3.600000000, x[1, 2] = -0. }:
#
# You can access the values to which the parameters
# in sol have been equated, by using
#
#    eval(varName, sol)
#
# as in the following
#
  eval( c[1,1], sol);
  eval( c[1,2], sol);
  eval( u[1,1], sol);
  eval( u[1,1], sol);
  eval( x[1,1], sol);
  eval( x[1,2], sol);

                          18.00000000

                              -0.

                         -0.9000000000

                         -0.9000000000

                          3.600000000

                              -0.



Of course if tou really, reallly want to convert these to assignments, then just apply the assign command to sol[], in an elementwise fashion, as in the code below

  restart;
  sol := { c[1, 1] = 18.00000000, c[1, 2] = -0., u[1, 1] = -.9000000000,
           u[1, 2] = 0., x[1, 1] = 3.600000000, x[1, 2] = -0. }:
#
# If you really, really want to make *assignments* then just
# apply the assign() command elementwise to sol
#
  assign~(sol):
  c[1,1];
  c[1,2];
  u[1,1];
  u[1,1];
  x[1,1];
  x[1,2];

 

more of an illustration.

The attached worksheet defines a curve in 3D, as it happens, a conical helix, (you do not supply the curve you are interested in, so I feel free to use anything I want), together with tangents at various points. As a visual check the curve and the tangents are plotted. The tangent at an arbitray point is also calculated. So please expalin clearly for your curve (which you should specify exactly), what do you find difficult?

  restart;
  with(VectorCalculus):
  SetCoordinates(cartesian[x,y,z]):
#
# Parametrically define a conical helix - just
# because one needs some sort of curve to work
# with and the OP does not provide one
#
  v:= Vector( [t/2,2*Pi*t,t],
              coordinates=cylindrical[r,theta, Z]
            ):
#
# Evaluate the tangent to this conical helix
# at various values of the parmeter 't'
#
  T1:=TangentLine( v, t=1):
  T2:=TangentLine( v, t=2):
  T3:=TangentLine( v, t=3):
#
# Output the tangent curve (vectorially) for
# some arbitrary value of the parameter which
# defines the curve
#
  Ta:=TangentLine( v, t=a);
#
# Plot the curve and the three tangents which
# have been explicitly defined - just so that
# one can visuallu check that theese are indeed
# tangents
#
  plots:-display( [ SpaceCurve
                    ( T1,
                      x=0..1,
                      color=black,
                      thickness=4
                    ),
                    SpaceCurve
                    ( T2,
                      x=3/4..5/4,
                      color=blue,
                      thickness=4
                    ),
                    SpaceCurve
                    ( T3,
                      x=4/3..5/3,
                      color=green,
                      thickness=4
                    ),
                    SpaceCurve
                    ( v,
                      t=0..Pi,
                      color=red,
                      thickness=4
                    )
                  ],
                  scaling=constrained
                )

Vector(3, {(1) = x, (2) = -(cos(2*Pi*a)^2*Pi*a^2+sin(2*Pi*a)^2*Pi*a^2-2*cos(2*Pi*a)*Pi*a*x-sin(2*Pi*a)*x)/(-2*Pi*a*sin(2*Pi*a)+cos(2*Pi*a)), (3) = a-(a*cos(2*Pi*a)-2*x)*sqrt(a^2*cos(2*Pi*a)^2+a^2*sin(2*Pi*a)^2)/(a*csgn(a)*(-2*Pi*a*sin(2*Pi*a)+cos(2*Pi*a)))})

 

 

 

Download 3Dtangents.mw

the plot of the analytic solution is the function y(t) versus the function x(t), I assume you want the same thing from the numeric solution. The method for this is shown in the attached.

Inline display - broken AGAIN

ytVsxt.mw

that the directory exists and is wrtable, using FileTools commands - for example

  restart;
  with(FileTools):
#
# Change the following directory name to something
# appropriate for wuor machine
#
  dirName:="C:/Users/TomLeslie/Desktop":
#
# Check that the directory exists
#
  Exists(dirName);
#
# Check that it is a directory
#
  IsDirectory(dirName);
#
# Check that the directory is writable
#
  IsWritable( "C:/Users/TomLeslie/Desktop" );
#
# Check whether the file you are interested in
# exists already
#
  fileName:="tuples.mw":
  Exists( cat(dirName, "/", fileName));
  fileName:="doesNotExist.mw":
  Exists( cat(dirName, "/", fileName));

                              true

                              true

                              true

                              true

                             false

 

 

 

tuple10:=proc(searchstop,diff1,diff2,diff3,diff4,diff5,diff6);

has only seven parameters. However in both of the examples (one in the worksheet, and one in the text of your question), you supply eleven arguments. It is not obvous (to me at least) what you want (if anything) to do with the last four arguments. As written, your procedure iwill just ignore them.

I have assumed that you always want to pass an argument for 'searchstop', and at least two more arguments. As  written the attached will accept any number of arguments (>2) and print the results in the way you wish

  tuple10:= proc(searchstop);
                 local a, j,
                       counter:=1,
                       v:=[_passed][2..-1];
                 if _npassed < 3
                 then error "Procedure requires at least two arguments":
                 fi:
                 for a from 3 to searchstop by 2 do
                     if  {isprime~([ a, a+~(v)[] ])[]}={true}
                     then printf("%6d %6d", counter, a);
                          seq( `if`( j<>0,
                                     printf(" %6d", a+j),
                                     NULL
                                   ),
                               j in v
                             );
                          counter:=counter+1:
                          printf("\n");
                      fi;
                 od;
                 printf("\n");
            end proc:
  tuple10(100, 12); #Should cause Error
  tuple10(100, 12, 14);
  tuple10(100, 12, 14, 2);
  tuple10(100, 12, 14, 0, 0, 0, 0, 0, 0, 0, 2);

Error, (in tuple10) Procedure requires at least two arguments

 

     1      5     17     19
     2     17     29     31
     3     29     41     43
     4     47     59     61
     5     59     71     73
     6     89    101    103

     1      5     17     19      7
     2     17     29     31     19
     3     29     41     43     31
     4     59     71     73     61

     1      5     17     19      7
     2     17     29     31     19
     3     29     41     43     31
     4     59     71     73     61
 

 

 

Download tuples.mw

just because

  1. Alternatives are good
  2. I happpen to think that one should probably use Maple's geometry() package for ptoblems in - well "geometry"


 

  restart;
#
# specify the lengths of the sides
#
  sides:= [3, 4, 6]:
#
# Define a procedure which does all the necessary
# calculations
#
  consTri:= proc( L )

                  uses geometry:

                  local p__0, p__1, c__1, c__2, s__1, i, t,
                        sv:= sort( _passed );
                #
                # From the supplied values in the list L
                # check whether it is possible to contruct a
                # triangle. If not, then return an error
                #
                  if   sv[1]+sv[2] < sv[3]
                  then error "No triangle possible"
                  fi;
                #
                # Get the intersection of the two circles
                #
                  intersection
                  ( i,
                    circle
                    ( c__1,
                      [ point
                        ( p__0,
                          [0, 0]
                        ),
                        L[2]
                      ]
                    ),
                    circle
                    ( c__2,
                      [ point
                        ( p__1,
                          [L[1], 0]
                        ),
                        L[3]
                      ]
                    )
                  );
                #
                # Construct the triangle: ther will be two intersection
                # points in the list 'i', so just pick the first one
                #
                  triangle( t, [p__0, p__1, i[1]]):
                  return t;
            end proc:
#
# Run the procedure for the given values of the side
# lengths of the triangle
#
  z:=consTri(sides):
#
# Get the details of the result, assuming a triangle is
# possible
#
  geometry:-detail(z);
  geometry:-draw(z);

GeometryDetail(["name of the object", t], ["form of the object", triangle2d], ["method to define the triangle", points], ["the three vertices", [[0, 0], [3, 0], [-11/6, (1/6)*sqrt(455)]]])

 

 

 

 

 


 

Download doTri.mw

Since yyou don't actually supply the file you are interested in ( ie "Indifferenzkurve.csv") I can't produce the code to do this bu the appoach would be

  1. Import the whole file
  2. Split the resulting matrix into a list of columns using the the LinearAlgebra:Column() function
  3. Use a select() command to pick out only those columns whose first entry corrresponds to one of "E","T", and "S_P and S_TEV"
  4. combine these selected columns into a new matrix

This is actually pretty trivial - and if you had supplied the file "Indifferenzkurve.csv", probably someone here would have supplied you with the code to do it by now!

the same calculation - but in two conceptually different ways. Why should this matter? Well with floating-point arithmetic, sometimes it does!

When you use unapply(), it will evaluats its arguments before converting to a function definition. So the way you have defined the function f(), it will generate an expression contianing 10000 terms, each of which contains the passed argument 'r'. On the other hand, since you have placed unevaluaion quotes arounnd  the add() function in the definition of of the function g(), this will generate one single term to which the add() will be applied.

On a subsequent call to the function f(), the passed argument will be inserted into each of the 10000 terms in the function definition and the sum will be computed. On the other hand, a subsequent call to the function g() will insert the passed argument into a single term,  and the resulting sum will be computed. Essentially two different ways of doing the "same" (floating-point) calculation. Looks like exactly the same thing - doesn't it!! However if you do the (logically) same calcultion two different ways in floating point arithmetic, it is perfectly possible to get two different answers, depending on phenomena such as "rounding" or "catastrophic cancellation".

To resolve your problem, in the attached, I increased the setting of "Digits" to 50, so that all floating point calculations will be carried out to 50 digits - and the two results now agree. Isn't floating-point arithmetic wonderful!

  restart:
  Digits:=50:
  phi1 := GAMMA(-(1/2)*vst-8.333500000-(1/2)*r)*GAMMA((1/2)*vst+21/2+(1/2)*r); phi2 := GAMMA(16.66700000+r-2*vst)*GAMMA(2.166500000+vst);
  xi1 := -vst;
  xi2 := 16.66700000+r-2*vst;
  z := 37.52950222;
  K := 9.846618489*10^(-38)*33.330^(.5000000000*r+10.);

### Then I have the following sums (they were supposed to give the same results):
#
# The following is for illustration only so that OP
# can see the difference between the teo function
# definitions - note that the numeber of terms in the
# summation has been reduced to 2 in order to avoid
# "excessive" display. Thezse show two *different*
# ways to do the same calculation, and in floating-
# point arithmetic, doing the "same" calculation
# two different ways can sometimes lead to very
# different results!
#
  
  f := unapply(K*add(phi1*(-1)^vst*z^(-xi1)/factorial(vst)+phi2*(-1)^vst*z^(-xi2)/(.5*factorial(vst)), vst = 0 .. 5), r);
  g := unapply(K*'add'(phi1*(-1)^vst*z^(-xi1)/factorial(vst)+phi2*(-1)^vst*z^(-xi2)/(.5*factorial(vst)), vst = 0 .. upto), [r, upto]);
 

GAMMA(-(1/2)*vst-8.333500000-(1/2)*r)*GAMMA((1/2)*vst+21/2+(1/2)*r)

 

GAMMA(16.66700000+r-2*vst)*GAMMA(2.166500000+vst)

 

-vst

 

16.66700000+r-2*vst

 

37.52950222

 

0.98466184890000000000000000000000000000000000000000e-37*33.330^(.5000000000*r+10.)

 

proc (r) options operator, arrow; 0.98466184890000000000000000000000000000000000000000e-37*33.330^(.5000000000*r+10.)*(1.0*GAMMA(-8.333500000-(1/2)*r)*GAMMA(21/2+(1/2)*r)+2.1644890560726363641311847541769678873770256232756*GAMMA(16.66700000+r)*37.52950222^(-16.66700000-r)-37.52950222*GAMMA(-8.8335000000000000000000000000000000000000000000000-(1/2)*r)*GAMMA(11+(1/2)*r)-4.6893655399813666828902117699244009280023260128266*GAMMA(14.66700000+r)*37.52950222^(-14.66700000-r)+704.23176844049246420000000000000000000000000000000*GAMMA(-9.333500000-(1/2)*r)*GAMMA(23/2+(1/2)*r)+7.4244379911754988006859277847328077692596826598076*GAMMA(12.66700000+r)*37.52950222^(-12.66700000-r)-8809.8225723606626243623901746666666666666666666667*GAMMA(-9.8335000000000000000000000000000000000000000000000-(1/2)*r)*GAMMA(12+(1/2)*r)-10.311306963410905251019306038363081190206822600696*GAMMA(10.66700000+r)*37.52950222^(-10.66700000-r)+82657.063946803899650419837036164713606666666666667*GAMMA(-10.333500000-(1/2)*r)*GAMMA(25/2+(1/2)*r)+13.318341856615610494847811161800714742300887241624*GAMMA(8.66700000+r)*37.52950222^(-8.66700000-r)-620415.69297805178276701769959615636791741217469333*GAMMA(-10.833500000000000000000000000000000000000000000000-(1/2)*r)*GAMMA(13+(1/2)*r)-16.425511011764032423295805505848821491679684235095*GAMMA(6.66700000+r)*37.52950222^(-6.66700000-r)) end proc

 

proc (r, upto) options operator, arrow; 0.98466184890000000000000000000000000000000000000000e-37*33.330^(.5000000000*r+10.)*add(GAMMA(-(1/2)*vst-8.333500000-(1/2)*r)*GAMMA((1/2)*vst+21/2+(1/2)*r)*(-1)^vst*37.52950222^vst/factorial(vst)+2.0000000000000000000000000000000000000000000000000*GAMMA(16.66700000+r-2*vst)*GAMMA(2.166500000+vst)*(-1)^vst*37.52950222^(-16.66700000-r+2*vst)/factorial(vst), vst = 0 .. upto) end proc

(1)

#
# Now redefine 'f' and 'g' and do the calculation for real
#
  f := unapply(K*add(phi1*(-1)^vst*z^(-xi1)/factorial(vst)+phi2*(-1)^vst*z^(-xi2)/(.5*factorial(vst)), vst = 0 .. 10000), r):
  g := unapply(K*'add'(phi1*(-1)^vst*z^(-xi1)/factorial(vst)+phi2*(-1)^vst*z^(-xi2)/(.5*factorial(vst)), vst = 0 .. upto), [r, upto]):  evalf(f(1)/f(0));
  evalf(g(1,10000)/g(0,10000));

3.0821078229312707837291844364491966196978061963651

 

3.0821078229312709283098875637620572421420677248231

(2)

 

Download digFloat.mw

 

  1. You have syntax issues - your entries t = time, rage = 0 .. 1, should be time=t, range=0..4. The end points of the range, must correspond with the values you have defined in the boundary conditions (which are x=0 and x=4).
  2. Maple's numeric PDE solvers cannot handle boundary conditions with derivatives which are parallel to the boundary, in your case a derivative with respect to 'x' at the value t=0. and you have D[1](u)(x, 0) = 0. Derivatives must be normal to the boundary - so, for example, D[2](u)(x, 0) = 0 would be acceptable - although it is not the condition that you want!

Thus the code

PDE := diff(u(x, t), x, x) + diff(u(x, t), t, t)/0.5^2 - 2*diff(u(x, t), x, t)/0.5^2 = -0.0013*u(x, t) + 8.6510*u(x, t)^3;
IBC := {u(0, t) = 0.01, u(4, t) = 0, u(x, 0) = 0, D[2](u)(x, 0) = 0};
pds := pdsolve(PDE, IBC, numeric, time=t, range = 0 .. 4);

will execute - although the derivative boundary condition is not what you want

was a straightforward translation from 'linalg()' to 'LinearAlgebra()'. I didn''t pay much attention to the calculation you were attempting but it looks like you want to rotate/translate an arbitrary parabola, to one which has its vertex at the origin, and its axis paralle with the x-axis.

There are easier ways to do this! See the attached, which unfortunately won't display inline, but it produces the following output and plots

GeometryDetail(["name of the object",        pa],
               ["form of the object",        parabola2d],
               ["vertex",                    [-17/40, 17/20]],
               ["focus",                     [-1/40, 1/20]],
               ["directrix",                 -1/5*x*sqrt(5) + 2/5*sqrt(5)*y - 33/40*sqrt(5) = 0],
               ["equation of the parabola",   4*x^2 + 4*x*y + y^2 - 8*x + 16*y - 17 = 0])

GeometryDetail(["name of the object",       pc],
               ["form of the object",       parabola2d],
               ["vertex",                   [0, 0]],
               ["focus",                    [2/5*sqrt(5), 0]],
               ["directrix",                -2/5*sqrt(5) - x = 0],
               ["equation of the parabola", -8*x*sqrt(5) + 5*y^2 = 0])

parabolae.mw

 

First 30 31 32 33 34 35 36 Last Page 32 of 207