acer

32343 Reputation

29 Badges

19 years, 327 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Two basic approaches to plotting a surface from 3D data are interpolation and smoothing. In the former, the surface goes through the data points exactly.

Your "grid" of data points is not full. There are gaps. If you had a full grid (lattice) of x-z data points then plots:-surfdata would handle it quickly, to interpolate a surface.

Stock Maple does not presently have a command to interpolate (higher than linearly) an irregularly spaced set of 3D data points to get a smooth surface. The `surfdata` command can produce a collection of polygon plots as a linear interpolation. But it's not very attractive, in part because of shading and partly because it's only piecewise smooth.

I converted your data to csv, after chopping off the first row of the spreadsheet.

restart:
M:=ImportMatrix("y0.csv",source=csv,datatype=float[8]):

For reasons I don't fully understand, `surfdata` sometimes stalls while trying to handlt the full 383x3 Matrix. I split it into parts, manually. (.. and even then, sometimes it would hang, and then immediately retrying the problematic call would immediately succeed. Weird.)

P1:=plots:-surfdata(M[1..162],0.0..0.4,0.05..1.0):
P2:=plots:-surfdata(M[142..225],0.45..0.55,0.0..1.0):
P3:=plots:-surfdata(M[205..315],0.60..0.80,0.0..1.0):
P3a:=plots:-surfdata(M[298..336],0.80..0.85,0.0..1.0):
P4:=plots:-surfdata(M[316..],0.85..1.0,0.0..1.0):
plots:-display(P1,P2,P3,P3a,P4);

A simpler, if slower and more computationally intensive approach is to do "lowess" smoothing. This has quite a few options to it, but the following seems not too bad, and the outliers don't seem to be painfully far from the surface.

Statistics:-ScatterPlot3D(M,lowess=true,bandwidth=0.15,fitorder=2,showpoints=true);

Yet another approach would be interpolate repeatedly in just 1 dimension, using the original data, so as to form a full grid (Matrix). For example, for just one portion, to turn this,

M[110..125,1..3];
         [0.300000000000000                  0.  -60.3200000000000]
         [                                                        ]
         [0.300000000000000  0.0500000000000000  -62.8000000000000]
         [                                                        ]
         [0.300000000000000   0.100000000000000  -63.6600000000000]
         [                                                        ]
         [0.300000000000000   0.150000000000000  -71.2700000000000]
         [                                                        ]
         [0.300000000000000   0.200000000000000  -60.2500000000000]
         [                                                        ]
         [0.300000000000000   0.250000000000000  -56.1800000000000]
         [                                                        ]
         [0.300000000000000   0.300000000000000  -49.9900000000000]
         [                                                        ]
         [0.300000000000000   0.500000000000000  -53.5200000000000]
         [                                                        ]
         [0.300000000000000   0.550000000000000  -47.0100000000000]
         [                                                        ]
         [0.300000000000000   0.600000000000000  -57.0500000000000]
         [                                                        ]
         [0.300000000000000   0.650000000000000  -56.8900000000000]
         [                                                        ]
         [0.300000000000000   0.700000000000000  -56.7300000000000]
         [                                                        ]
         [0.300000000000000   0.750000000000000  -55.5200000000000]
         [                                                        ]
         [0.300000000000000   0.850000000000000  -50.2100000000000]
         [                                                        ]
         [0.300000000000000   0.950000000000000  -56.4100000000000]
         [                                                        ]
         [0.300000000000000                  1.  -60.3200000000000]

into this,

Matrix([Vector(21,0.3),
        Vector(21,i->(i-1)*0.05),
        CurveFitting:-ArrayInterpolation(M[110..125,2..3],
                                         Vector(21,i->(i-1)*0.05))],
        datatype=float[8]);
         [0.300000000000000                  0.  -60.3200000000000]
         [                                                        ]
         [0.300000000000000  0.0500000000000000  -62.8000000000000]
         [                                                        ]
         [0.300000000000000   0.100000000000000  -63.6600000000000]
         [                                                        ]
         [0.300000000000000   0.150000000000000  -71.2700000000000]
         [                                                        ]
         [0.300000000000000   0.200000000000000  -60.2500000000000]
         [                                                        ]
         [0.300000000000000   0.250000000000000  -56.1800000000000]
         [                                                        ]
         [0.300000000000000   0.300000000000000  -49.9900000000000]
         [                                                        ]
         [0.300000000000000   0.350000000000000  -50.8725000000000]
         [                                                        ]
         [0.300000000000000   0.400000000000000  -51.7550000000000]
         [                                                        ]
         [0.300000000000000   0.450000000000000  -52.6375000000000]
         [                                                        ]
         [0.300000000000000   0.500000000000000  -53.5200000000000]
         [                                                        ]
         [0.300000000000000   0.550000000000000  -47.0100000000000]
         [                                                        ]
         [0.300000000000000   0.600000000000000  -57.0500000000000]
         [                                                        ]
         [0.300000000000000   0.650000000000000  -56.8900000000000]
         [                                                        ]
         [0.300000000000000   0.700000000000000  -56.7300000000000]
         [                                                        ]
         [0.300000000000000   0.750000000000000  -55.5200000000000]
         [                                                        ]
         [0.300000000000000   0.800000000000000  -52.8650000000000]
         [                                                        ]
         [0.300000000000000   0.850000000000000  -50.2100000000000]
         [                                                        ]
         [0.300000000000000   0.900000000000000  -53.3100000000000]
         [                                                        ]
         [0.300000000000000   0.950000000000000  -56.4100000000000]
         [                                                        ]
         [0.300000000000000                  1.  -60.3200000000000]

If that were done for all the sets of x-values, then (only) all the final y-column results could be put into just a single Matrix which could be fed to `surfdata` (and the x- and z-ranges supplied as simple range arguments). I haven't done this.

acer

There are several other ways. Here are two.

a:={1,2}:

Vector([a[]]);
                                     [1]
                                     [ ]
                                     [2]

<a[]>;
                                     [1]
                                     [ ]
                                     [2]

But note that you may not always get the ordering of entries that you expect, which in turn could possibly make coding the construction of your Matrices difficult.

restart:

a:={2,11,-1}:
<a[]>;
                                    [-1]
                                    [  ]
                                    [ 2]
                                    [  ]
                                    [11]

a:={x,c,X}:
<a[]>;
                                     [X]
                                     [ ]
                                     [c]
                                     [ ]
                                     [x]

Some routines can accept certain of their arguments in either `list` or `set` form, where the ordering of names may be repected when using `list` input. I am not sure whether that fact would help your case. An example is `solve`,

restart:

solve({a+b-4,a-b-1},[a,b]);
                              [[    5      3]]
                              [[a = -, b = -]]
                              [[    2      2]]

solve({a+b-4,a-b-1},[b,a]);
                              [[    3      5]]
                              [[b = -, a = -]]
                              [[    2      2]]

Sometimes there are other ways around that, including 2-argument eval.

restart:

sol := solve({a+b-4,a-b-1},{a,b});
                                   /    5      3\ 
                           sol := { a = -, b = - }
                                   \    2      2/ 

eval([b,a],sol);
                                   [3  5]
                                   [-, -]
                                   [2  2]

It might be easier to help more if you could show a more detailed problematic example.

acer

> restart:
> d:=evalf(Pi,1);         
                                    d := 3.

> evalf(subs(x=d,1/x),1); 
                                      0.3

> evalf(subs(x=d,3/x),1);
                                      0.9

> restart:
> d:=evalf(Pi,2);        
                                   d := 3.1

> evalf(subs(x=d,1/x),2);
                                     0.32

> evalf(subs(x=d,3/x),2);
                                     0.96

> restart:               
> d:=evalf(Pi,3);        
                                   d := 3.14

> evalf(subs(x=d,1/x),3);
                                     0.318

> evalf(subs(x=d,3/x),3);
                                     0.954

And, for interest, following this,

 restart:
> ee:=y/x:
> d:=evalf(Pi,1);
                                    d := 3.

> evalf(eval(ee,[x=d,y=3]),1);  
                                      1.

> evalf(subs(x=d,y=3,ee),1);
                                      0.9

> restart:
> invee:=x/y:
> ee:=1/invee;
                                   ee := y/x

> d:=evalf(Pi,1);
                                    d := 3.

> evalf(eval(ee,[x=d,y=3]),1);
                                      0.9

> evalf(subs(x=d,y=3,ee),1);
                                      0.9

acer

Did you intend a multiplication sign between the first instance of `lambda` and the opening bracket that follows it?

acer

The command that does what you've described (in your followup note to Carl) is `coeff`.

X:=X_FS2(s)=xp0*s+x0:

XP:=diff(X_FS2(s),s)=xp0:

coeff(op(2,X),x0);
                               1

coeff(op(2,XP),x0);
                               0

acer

My 64bit Maple 17.02 Standard GUI on Windows 7 Pro prints only the empty character box as output when I enter the Maple 1D Notation code,

`&#9813;`;

Can this be reduced to a Maple font issue then?

N:=sscanf(`2655`,"%x")[];
                              9813

convert(N,hex);;
                              2655

Hence I actually tried it as,

cat(`&#`,N,`;`);

and of course that could be sprintf'd instead, to get a string rather than a name.

I see that I can get a text plot involving the square-root symbol if I instead do, say,

plots:-display(plots:-textplot([1,1,"&#8730;"]));

acer

You have assigned an expression to the name `w`, not a procedure. So it's not appropropriate to then use `w` in a function call such as `w(x)`.

Like `plot` and `evalf(Int(...))` and several other commands, `fsolve` can work with either operator form (procedures, say) or expressions. Mixing these up is a common mistake (so don't feel bad about it).

Hence you could be calling fsolve like,

   fsolve(w = 0, x = kk .. kk+1);

instead of as your original,

   fsolve(w(x) = 0, x = kk .. kk+1);

You might get better performance here by using RootFinding:-NextZero instead of fsolve for this problem. For that you would need to produce an operator (procedure) by unapplying expression `w` with respect to name `x`. And then you could apply `NextZero` repeatedly, such as,

wf:=unapply(w,x):
RootFinding:-NextZero(wf,5);
                          6.584620042

RootFinding:-NextZero(wf,%);
                          12.72324078

RootFinding:-NextZero(wf,%);
                          18.95497141

Or you could use it in a fancier way, such as in my answer here.

Note also that your code using `fsolve` may be doing inadvertant duplication of attempts (when it fails to find a root), due to your particular check of whether `zz` is of type `float`. If you are running this code at the top level then your type check call type(zz,float) is going to repeat each failed attempt where `zz` is the unevaluated function call (to itself) that `fsolve` returns. This code would run faster if the check were like type(eval(zz,1), float) or if the computation were run within a procedure having local variable `zz` instead. The point is that full evaluation of the argument `zz` as the argument of the call to `type` will reevaluate those returned calls to fsolve and so also repeat the failing computations. See here for some notes on this.

acer

Change the instance of Textfield[TFxv] to TextField[TFxv] to correct the typo.

acer

Try it as,

int(diff(w(s),s,s),s=0..L,continuous);

You may wish to convert a result involving both `diff` and `D` to just one or the other.

acer

restart:

assume(x>0,1>x):

L:=[x^3,x^4,x^2,x,1,0];

                            [  3    4    2          ]
                       L := [x~ , x~ , x~ , x~, 1, 0]

sort( L ); # the usual, and not what is wanted

                          [            2    3    4]
                          [0, 1, x~, x~ , x~ , x~ ]

sort( L, (a,b)->is(a<b) );

                          [     4    3    2       ]
                          [0, x~ , x~ , x~ , x~, 1]

sort( L, (a,b)->is(a>b) );

                          [         2    3    4   ]
                          [1, x~, x~ , x~ , x~ , 0]

acer

That should be sin(x) not sinx.

acer

Those should be single left quotes in that call to lprint, but you appear to have them as single right quotes.

You could also do the printing by using printf instead of lprint, ie, replace

lprint(r1, `=`, q, `*`, r2, `+`, r3);

by, say,

printf("%a = %a * %a + %a\n", r1,q,r2,r3);

acer

restart:

MyHandler := proc(operator,operands,default_value)
   NumericStatus( division_by_zero = false );
   return infinity;
end proc:

NumericEventHandler(division_by_zero=MyHandler):

for i in {1, 2/0, -3, 1/4, 5} do
if i::posint then print(i)  fi;
od;

                               1
                               5

select(x->is(x::posint), {1, 2/0, -3, 1/4, 5});

                             {1, 5}

acer

So, something like this?

restart:

lambda0:=PL-R3*x:
Psi0:=PL+R3*S0*(R1-1)-R1*R3*x:
S0:=(Q-1)/Q:

P:=piecewise(x<S0,lambda0,x>S0,Psi0):

plot3d(eval(P,[R3=-5,k=4,R1=0.0006,Q=1.2]),x=0..1,PL=0..1,labels=[x,PL,'P']);

acer

You could try simplification with side relations, ie, see ?simplify,siderels

restart:

ee:=-1/4*m*omega*sin(1/2*omega*T)*(2*cos(1/2*omega*T)^2*xa^2      
    +2*cos(1/2*omega*T)^2*xb^2-xa^2-2*xa*xb-xb^2)/                
    (cos(1/2*omega*T)^2-1)/cos(1/2*omega*T):                      

EE:=simplify(combine(simplify(simplify(ee,                        
             {cos(omega*T/2)^2-1=-sin(omega*T/2)^2}),size)),size);

                                  2     2
                      omega m ((xa  + xb ) cos(omega T) - 2 xa xb)
            EE := 1/2 --------------------------------------------
                                      sin(omega T)

length(ee), length(EE);

                                   247, 113

acer

First 246 247 248 249 250 251 252 Last Page 248 of 336