Robert Israel

6577 Reputation

21 Badges

18 years, 209 days
University of British Columbia
Associate Professor Emeritus
North York, Ontario, Canada

MaplePrimes Activity


These are answers submitted by Robert Israel

I get (with yd replaced by yd1, and after with(Statistics))

N2 := [K2 = 48.4344309337249, T12 = 606.267114612954, T22 = 72.5280784895289, Tv2 = 263.567268383090]

It looks optimal enough to me.  Why do you say it isn't?

You seem to be using z for both an independent variable and a dependent variable (z(t)).  Is that supposed to be the same z?  If so, you really only have one independent variable t, so it is a system of ODE's, not PDE's.

Hopefully your (x,y) values are organized in a grid of, say, m rows and n columns (first the n points of the first row, then the n points of the second row, etc).  Then if M is the Matrix you get from the Import Data assistant, you can try

> plots[surfdata](ArrayTools[Reshape](M,[n,m,3]), style=patchcontour);

Ah, so the error comes from the part of your program that you didn't show us. And until you show us more, it's really hard to be helpful.

For future reference: if you give us a piece of code and ask what is happening, please make sure that the behaviour you're asking about occurs when you run that piece of code in a new Maple session. 

> t0:= .0104167; Vm:= 100; a:= 5800;
pm:= 11.83; pim:= 6.296; Dm:= 382.7; L:= 80;
pdes:= [diff(cm(x,t),t) = Dm * diff(cm(x,t),x$2)-Vm*diff(cm(x,t),x) - pm*(cm(x,t)-cim(x,t)),
diff(cim(x,t),t)=pim*(cm(x,t)-cim(x,t))];
ibc:= [cm(x,0)=0,cim(x,0)=0,cm(0,t)-Dm/Vm*D[1](cm)(0,t)=a*Heaviside(t0-t),
cm(L,t)+Dm/Vm*D[1](cm)(L,t)=0];
Sol:= pdsolve(pdes,ibc,numeric, timestep=0.001);
Sol:-plot3d(cm(x,t),t=0..2,axes=frame, orientation = [-50,70], labels=[x,t,cm(x,t)]);
 Sol:-plot3d(cim(x,t),t=0..2,axes=frame, orientation = [-50,70], labels=[x,t,cim(x,t)]);


Here's a 2 x 3 example:

> with(LinearAlgebra):
A:= evalf(<<1,2>|<-3,4>|<5,-6>>);
U,S,Vt:= SingularValues(A,output=['U','S','Vt']);
with(plottools): with(plots):
P1:= display([seq(arrow(Row(Vt,i),colour=red),i=1..3),
sphere([0,0,0],1,style=patchnogrid,transparency=0.8),
textplot3d([seq([1.1*Vt[i,1],1.1*Vt[i,2],1.1*Vt[i,3],v[i]],i=1..3)],colour=black)],
     scaling=constrained,axes=box,orientation=[-30,60]):
C:= cos(t)*S[1]*Column(U,1) + sin(t)*S[2]*Column(U,2):
theta:= arctan(U[2,1],U[1,1]):
P2:= display([
seq(arrow(S[i]*Column(U,i),width=0.1,head_length=0.6,head_width=0.3),i=1..2),
plottools[rotate](plottools[ellipse]([0,0],S[1],S[2],filled=true,colour=gray),theta),
textplot([seq([(0.5+S[i])*U[1,i],(0.5+S[i])*U[2,i],s[i]*u[i]],i=1..2)])],
scaling=constrained):
display(Array([P1,P2]));


It still looks like your first plot.

:= is for assignments, = is for equations.  I think you are talking about the following system of equations (I don't know what that 1S[i] is doing in the assignment to b[i]: I deleted the 1.

By the way, don't reduce Digits below the default 10.  It can cause severe roundoff-error problems.  If you only want to see 6 digits of the answers, use the "Round screen display to" option in Options, Precision (under the Tools menu).  In fact, I would actually increase Digits in this case, since it appears that your system is very ill-conditioned.

> s:=140:
T:=1:
M:=40:
N:=10:
k:=T/N:
h:=s/M:
r:=0.05:
W:=20:
for i from 0 to M do
S[i]:=i*h:
u[i,0]:=W:
od:
for j from 0 to N do  
u[M,j+1]:=s:
u[0,j+1]:=0:
od:
for i from 1 to M do
a[i]:=(r*k*S[i]/h-k*S[i]^2/h^2);
b[i]:=S[i]^2*k/h^2;
c[i]:=-(0.5*r*k*S[i]/h+k*S[i]^2/h^2);
od:
eqs:= [seq(seq(u[i,j]=a[i]*u[i-1,j+1]+b[i]*u[i,j+1]+c[i]*u[i+1,j+1], j=0..N),i=1..M-1)];
Digits:= 20;
with(LinearAlgebra):
vars:= convert(indets(eqs),list);
A,b:= GenerateMatrix(eqs,vars):
X:= LinearSolve(A,b);
[seq(vars[i]=evalf(X[i],6), i=1..429)];

[u[1,1] = -231.037, u[1,2] = 1753.49, u[1,3] = -20301.6, u[1,4] = 178954., u[1,5] = -.184263e7, u[1,6] = .173651e8, u[1,7] = -.171938e9, u[1,8] = .165582e10, u[1,9] = -.161953e11, u[1,10] = .157034e12, u[1,11] = -.153006e13, u[2,1] = -420.524, u[2,2] = 3964.74, u[2,3] = -36913.6, u[2,4] = 372654., u[2,5] = -.354358e7, u[2,6] = .349184e8, u[2,7] = -.337160e9, u[2,8] = .329288e10, u[2,9] = -.319547e11, u[2,10] = .311207e12, u[2,11] = -.302478e13, u[3,1] = -242.235, u[3,2] = 3265.58, u[3,3] = -26697.7, u[3,4] = 286872., u[3,5] = -.264558e7, u[3,6] = .265149e8, u[3,7] = -.253646e9, u[3,8] = .249022e10, u[3,9] = -.240952e11, u[3,10] = .235048e12, u[3,11] = -.228246e13, u[4,1] = 147.826, u[4,2] = -360.924, u[4,3] = 5922.94, u[4,4] = -49494.7, u[4,5] = 515891., u[4,6] = -.484162e7, u[4,7] = .480331e8, u[4,8] = -.462091e9, u[4,9] = .452228e10, u[4,10] = -.438349e11, u[4,11] = .427183e12, u[5,1] = 372.207, u[5,2] = -3655.23, u[5,3] = 32310.6, u[5,4] = -334392., u[5,5] = .313972e7, u[5,6] = -.311529e8, u[5,7] = .299662e9, u[5,8] = -.293288e10, u[5,9] = .284274e11, u[5,10] = -.277039e12, u[5,11] = .269168e13, u[6,1] = 216.775, u[6,2] = -3429.65, u[6,3] = 27770.1, u[6,4] = -296833., u[6,5] = .274900e7, u[6,6] = -.274781e8, u[6,7] = .263254e9, u[6,8] = -.258236e10, u[6,9] = .249985e11, u[6,10] = -.243795e12, u[6,11] = .236775e13, u[7,1] = -157.230, u[7,2] = 134.345, u[7,3] = -3304.76, u[7,4] = 26946.9, u[7,5] = -280931., u[7,6] = .264049e7, u[7,7] = -.261689e8, u[7,8] = .251901e9, u[7,9] = -.246442e10, u[7,10] = .238923e11, u[7,11] = -.232812e12, u[8,1] = -375.199, u[8,2] = 3558.87, u[8,3] = -30793.9, u[8,4] = 321187., u[8,5] = -.300506e7, u[8,6] = .298730e8, u[8,7] = -.287056e9, u[8,8] = .281112e10, u[8,9] = -.272385e11, u[8,10] = .265501e12, u[8,11] = -.257931e13, u[9,1] = -221.384, u[9,2] = 3473.14, u[9,3] = -27978.5, u[9,4] = 298288., u[9,5] = -.276742e7, u[9,6] = .276322e8, u[9,7] = -.264891e9, u[9,8] = .259752e10, u[9,9] = -.251502e11, u[9,10] = .245247e12, u[9,11] = -.238200e13, u[10,1] = 148.847, u[10,2] = -38.5246, u[10,3] = 2209.47, u[10,4] = -17611.6, u[10,5] = 183608., u[10,6] = -.172838e7, u[10,7] = .171118e8, u[10,8] = -.164814e9, u[10,9] = .161189e10, u[10,10] = -.156300e11, u[10,11] = .152287e12, u[11,1] = 366.209, u[11,2] = -3500.43, u[11,3] = 29977.0, u[11,4] = -313844., u[11,5] = .293162e7, u[11,6] = -.291679e8, u[11,7] = .280150e9, u[11,8] = -.274420e10, u[11,9] = .265863e11, u[11,10] = -.259164e12, u[11,11] = .251764e13, u[12,1] = 215.895, u[12,2] = -3484.43, u[12,3] = 28003.2, u[12,4] = -298113., u[12,5] = .276850e7, u[12,6] = -.276268e8, u[12,7] = .264925e9, u[12,8] = -.259739e10, u[12,9] = .251514e11, u[12,10] = -.245245e12, u[12,11] = .238205e13, u[13,1] = -149.865, u[13,2] = -13.5462, u[13,3] = -1603.56, u[13,4] = 12453.4, u[13,5] = -129940., u[13,6] = .122469e7, u[13,7] = -.121145e8, u[13,8] = .116740e9, u[13,9] = -.114140e10, u[13,10] = .110696e11, u[13,11] = -.107844e12, u[14,1] = -365.410, u[14,2] = 3459.69, u[14,3] = -29441.6, u[14,4] = 308920., u[14,5] = -.288298e7, u[14,6] = .286978e8, u[14,7] = -.275563e9, u[14,8] = .269966e10, u[14,9] = -.261527e11, u[14,10] = .254949e12, u[14,11] = -.247663e13, u[15,1] = -216.714, u[15,2] = 3485.61, u[15,3] = -27970.3, u[15,4] = 297482., u[15,5] = -.276433e7, u[15,6] = .275753e8, u[15,7] = -.264484e9, u[15,8] = .259277e10, u[15,9] = -.251082e11, u[15,10] = .244816e12, u[15,11] = -.237793e13, u[16,1] = 146.346, u[16,2] = 47.0026, u[16,3] = 1216.18, u[16,4] = -9149.90, u[16,5] = 95660.0, u[16,6] = -902441., u[16,7] = .892036e7, u[16,8] = -.859968e8, u[16,9] = .840612e9, u[16,10] = -.815355e10, u[16,11] = .794289e11, u[17,1] = 361.037, u[17,2] = -3428.08, u[17,3] = 29051.9, u[17,4] = -305273., u[17,5] = .284726e7, u[17,6] = -.283510e8, u[17,7] = .272187e9, u[17,8] = -.266684e10, u[17,9] = .258334e11, u[17,10] = -.251844e12, u[17,11] = .244642e13, u[18,1] = 214.115, u[18,2] = -3482.31, u[18,3] = 27916.8, u[18,4] = -296719., u[18,5] = .275839e7, u[18,6] = -.275093e8, u[18,7] = .263886e9, u[18,8] = -.258671e10, u[18,9] = .250507e11, u[18,10] = -.244249e12, u[18,11] = .237245e13, u[19,1] = -146.333, u[19,2] = -70.2692, u[19,3] = -945.551, u[19,4] = 6834.98, u[19,5] = -71705.3, u[19,6] = 676892., u[19,7] = -.668677e7, u[19,8] = .644876e8, u[19,9] = -.630229e9, u[19,10] = .611365e10, u[19,11] = -.595530e11, u[20,1] = -359.965, u[20,2] = 3402.46, u[20,3] = -28749.2, u[20,4] = 302401., u[20,5] = -.281931e7, u[20,6] = .280788e8, u[20,7] = -.269543e9, u[20,8] = .264110e10, u[20,9] = -.255831e11, u[20,10] = .249409e12, u[20,11] = -.242275e13, u[21,1] = -214.230, u[21,2] = 3477.20, u[21,3] = -27856.2, u[21,4] = 295932., u[21,5] = -.275191e7, u[21,6] = .274398e8, u[21,7] = -.263245e9, u[21,8] = .258029e10, u[21,9] = -.249892e11, u[21,10] = .243646e12, u[21,11] = -.236662e13, u[22,1] = 144.253, u[22,2] = 87.6008, u[22,3] = 744.761, u[22,4] = -5111.33, u[22,5] = 53918.6, u[22,6] = -509155., u[22,7] = .502717e7, u[22,8] = -.484978e8, u[22,9] = .473876e9, u[22,10] = -.459739e10, u[22,11] = .447805e11, u[23,1] = 357.177, u[23,2] = -3380.84, u[23,3] = 28503.5, u[23,4] = -300045., u[23,5] = .279650e7, u[23,6] = -.278561e8, u[23,7] = .267381e9, u[23,8] = -.262005e10, u[23,9] = .253785e11, u[23,10] = -.247418e12, u[23,11] = .240338e13, u[24,1] = 212.628, u[24,2] = -3471.23, u[24,3] = 27794.0, u[24,4] = -295163., u[24,5] = .274539e7, u[24,6] = -.273711e8, u[24,7] = .262606e9, u[24,8] = -.257392e10, u[24,9] = .249281e11, u[24,10] = -.243046e12, u[24,11] = .236081e13, u[25,1] = -144.002, u[25,2] = -101.019, u[25,3] = -589.183, u[25,4] = 3770.67, u[25,5] = -40121.4, u[25,6] = 378844., u[25,7] = -.373897e7, u[25,8] = .360805e8, u[25,9] = -.352488e9, u[25,10] = .342004e10, u[25,11] = -.333109e11, u[26,1] = -356.168, u[26,2] = 3362.21, u[26,3] = -28297.7, u[26,4] = 298055., u[26,5] = -.277730e7, u[26,6] = .276682e8, u[26,7] = -.265560e9, u[26,8] = .260231e10, u[26,9] = -.252061e11, u[26,10] = .245740e12, u[26,11] = -.238707e13, u[27,1] = -212.535, u[27,2] = 3464.97, u[27,3] = -27732.7, u[27,4] = 294427., u[27,5] = -.273903e7, u[27,6] = .273049e8, u[27,7] = -.261986e9, u[27,8] = .256775e10, u[27,9] = -.248689e11, u[27,10] = .242466e12, u[27,11] = -.235519e13, u[28,1] = 142.567, u[28,2] = 111.800, u[28,3] = 464.615, u[28,4] = -2693.05, u[28,5] = 29060.0, u[28,6] = -274222., u[28,7] = .270556e7, u[28,8] = -.261146e8, u[28,9] = .255090e9, u[28,10] = -.247523e10, u[28,11] = .241074e11, u[29,1] = 354.152, u[29,2] = -3345.81, u[29,3] = 28121.3, u[29,4] = -296336., u[29,5] = .276077e7, u[29,6] = -.275062e8, u[29,7] = .263991e9, u[29,8] = -.258701e10, u[29,9] = .250575e11, u[29,10] = -.244294e12, u[29,11] = .237301e13, u[30,1] = 211.410, u[30,2] = -3458.65, u[30,3] = 27673.4, u[30,4] = -293728., u[30,5] = .273293e7, u[30,6] = -.272418e8, u[30,7] = .261392e9, u[30,8] = -.256187e10, u[30,9] = .248122e11, u[30,10] = -.241912e12, u[30,11] = .234982e13, u[31,1] = -142.255, u[31,2] = -120.661, u[31,3] = -362.286, u[31,4] = 1804.37, u[31,5] = -19960.7, u[31,6] = 188040., u[31,7] = -.185495e7, u[31,8] = .179081e8, u[31,9] = -.174905e9, u[31,10] = .169729e10, u[31,11] = -.165301e11, u[32,1] = -353.247, u[32,2] = 3331.20, u[32,3] = -27967.2, u[32,4] = 294825., u[32,5] = -.274628e7, u[32,6] = .273640e8, u[32,7] = -.262616e9, u[32,8] = .257359e10, u[32,9] = -.249272e11, u[32,10] = .243025e12, u[32,11] = -.236067e13, u[33,1] = -211.245, u[33,2] = 3452.43, u[33,3] = -27616.5, u[33,4] = 293068., u[33,5] = -.272710e7, u[33,6] = .271819e8, u[33,7] = -.260827e9, u[33,8] = .255628e10, u[33,9] = -.247583e11, u[33,10] = .241385e12, u[33,11] = -.234471e13, u[34,1] = 141.177, u[34,2] = 128.115, u[34,3] = 276.478, u[34,4] = -1056.29, u[34,5] = 12319.4, u[34,6] = -115573., u[34,7] = .114022e7, u[34,8] = -.110098e8, u[34,9] = .107518e9, u[34,10] = -.104344e10, u[34,11] = .101617e11, u[35,1] = 351.679, u[35,2] = -3318.02, u[35,3] = 27830.8, u[35,4] = -293479., u[35,5] = .273341e7, u[35,6] = -.272375e8, u[35,7] = .261393e9, u[35,8] = -.256165e10, u[35,9] = .248113e11, u[35,10] = -.241897e12, u[35,11] = .234971e13, u[36,1] = 210.391, u[36,2] = -3446.36, u[36,3] = 27562.1, u[36,4] = -292443., u[36,5] = .272156e7, u[36,6] = -.271251e8, u[36,7] = .260290e9, u[36,8] = -.255097e10, u[36,9] = .247072e11, u[36,10] = -.240885e12, u[36,11] = .233986e13, u[37,1] = -140.857, u[37,2] = -134.480, u[37,3] = -203.297, u[37,4] = 415.907, u[37,5] = -5793.05, u[37,6] = 53602.3, u[37,7] = -529458., u[37,8] = .511257e7, u[37,9] = -.499230e8, u[37,10] = .484518e9, u[37,11] = -.471842e10, u[38,1] = -350.872, u[38,2] = 3306.02, u[38,3] = -27708.4, u[38,4] = 292268., u[38,5] = -.272184e7, u[38,6] = .271237e8, u[38,7] = -.260293e9, u[38,8] = .255092e10, u[38,9] = -.247071e11, u[38,10] = .240882e12, u[38,11] = -.233984e13, u[39,1] = -210.201, u[39,2] = 3440.49, u[39,3] = -27510.2, u[39,4] = 291852., u[39,5] = -.271629e7, u[39,6] = .270712e8, u[39,7] = -.259781e9, u[39,8] = .254594e10, u[39,9] = -.246587e11, u[39,10] = .240411e12, u[39,11] = -.233526e13]

It works for me, in all versions of Maple that I tried.  You indicated that this is Maple 7.  I don't have Maple 7 available, but it works in Maple 6 and Maple 9.5, so if this was a bug in Maple 7 it has been fixed.  Are you sure this happens in a new Maple session with exactly the code you gave us (and no "...") ?

Here is one way.

pickrand:= proc(m, L)
local i;
i:= rand(1..nops(L))();
if m = 1 then [L[i]]
else [L[i], op(pickrand(m-1, subsop(i=NULL,L)))]
end if
end proc;

 

 

try...catch is the best solution, but you might also find the deprecated command traperror useful, requiring less programming.  For example:

> for x from -3 to 3 do traperror(1/x) end do;

                                 -1/3
                                 -1/2
                                  -1
                "numeric exception: division by zero"
                                  1
                                 1/2
                                 1/3

Whether it's from c++ or anything else is irrelevant.  If your program can produce a text file, Maple can read it.
See the help pages for fscanf, readline, or FileTools.  For binary data, things might be a bit trickier, but text files are sufficient for most purposes.  If you want a detailed example, tell us what format your data are in, or upload a sample.

randpoint produces a point whose spherical coordinates theta and phi are uniformly distributed on the intervals [0,2*Pi] and [0,Pi] respectively, but of course this is not uniformly distributed on the sphere.  That is a serious bug, I would say.  Here's a better way.

> n:= 100; # number of sample points
with(Statistics):
A:= Sample(Uniform(0,2*Pi), n);
B:= Sample(Uniform(-1,1), n);
Pts:= zip((a,b) -> <sqrt(1-b^2)*cos(a),sqrt(1-b^2)*sin(a),b>, A, B);
with(plots):
pointplot3d(Pts);

I think you should be able to do it this way.  Suppose the "l" slider is Slider0 and the "m" slider is Slider1.
Slider0's "action when value changes" should include the lines

 

Do(%Slider1(lower)=-%Slider0);
Do(%Slider1(upper)=%Slider0);



Both sliders should have "Snap to Axis Tick Marks" checked, and "Spacing of Minor Tick Marks" should be 1.

The word "table" has several different meanings in Maple.  Are you looking for something like this?

> A:= <a1, a2, a3>: B:= <b1, b2, b3>: C:= <c1, c2, c3>:
Matrix(<<`First heading` | `Second heading` | `Third heading`>,<A | B | C>>);

          [First heading    Second heading    Third heading]
          [                                                ]
          [     a1                b1               c1      ]
          [                                                ]
          [     a2                b2               c2      ]
          [                                                ]
          [     a3                b3               c3      ]





First 40 41 42 43 44 45 46 Last Page 42 of 138