pagan

5147 Reputation

23 Badges

17 years, 125 days

 

 

"A map that tried to pin down a sheep trail was just credible,

 but it was an optimistic map that tried to fix a the path made by the wind,

 or a path made across the grass by the shadow of flying birds."

                                                                 - _A Walk through H_, Peter Greenaway

 

MaplePrimes Activity


These are answers submitted by pagan

> restart:

> X:=<1,2,3,4,5,6,7,8,9,10>:
> Y:=<3.7,9.39,23.09,58.60,153.41,409.43,1103.63,2988.98,8112.08,22036.47>:

> eqn:=a*x+exp(b*x):

> solution:=Statistics:-Fit(eqn,X,Y,x,output=parametervalues);

             [a = 1.00044221090021557, b = 0.99999999560853414]

> solved_eqn:=eval(eqn,solution);

             1.00044221090021557 x + exp(0.99999999560853414 x)

> P1:=plot(<X|Y>,style=point,color=red):
> P2:=plot(solved_eqn,x=min(X)..max(X),color=green):
> plots:-display([P1,P2]);

 

If you don't supply the output=parametervalues option to Statistics:-Fit then it will by default return the equation (solved_eqn above). But you can do it as above if you want both the equation and the individual parameter values separately.

Using `add` is likely better here, but for what it's worth you may be able to also get by with uneval quotes.

> S2 := (p, k, n)-> piecewise(0 <= n and n < k, 1, n < 0, 0,
>                       sum('sum(p^y*(1-p)^(m-y)*S2(p, k, n-m), m = y+1 .. y+k-1)',
                            y = 1 .. n-k+1)):

> S2(p,4,4);
                                   2            3
              p (1 - p) + p (1 - p)  + p (1 - p) 

> S2 := (p, k, n)-> piecewise(0 <= n and n < k, 1, n < 0, 0,
                           add(add(p^y*(1-p)^(m-y)*S2(p, k, n-m), m = y+1 .. y+k-1),
                               y = 1 .. n-k+1)):

> S2(p,4,4);
                                   2            3
              p (1 - p) + p (1 - p)  + p (1 - p) 

Or for your other shorter example,

> S6 := (x)->piecewise(x <= 0, 1, sum(p^x+'S6'(x-a), a = 1 .. 5)):

> S6(2);
                            2          
                         5 p  + 5 p + 9

You might want to consider using `thisproc` to do the recursive reference (if only that you might wish to more easily change its name, or use it anonymously).

> S6 := (x)->piecewise(x <= 0, 1, sum(p^x+'thisproc'(x-a), a = 1 .. 5)):

> S6(2);
                            2          
                         5 p  + 5 p + 9

> S6 := (x)->piecewise(x <= 0, 1, add(p^x+thisproc(x-a), a = 1 .. 5)):

> S6(2);
                            2          
                         5 p  + 5 p + 9

And similarly for your longer S2 example.

I don't see any purely real solutions.

> restart:
> r1:=2:
> r2:=3:
> r4:=7:
> Gamma:=30:
> theta[2]:=20:
> theta[3]:=theta[4]-Gamma:
> expr1:=r2*cos(theta[2]) - r3*cos(theta[3])-r4*cos(theta[4])-r1:
> expr2:=r2*sin(theta[2])-r3*sin(theta[3])-r4*sin(theta[4]):
> fsolve({expr1,expr2}, {r3,theta[4]});

 fsolve({3 sin(20) - r3 sin(theta[4] - 30) - 7 sin(theta[4]), 

   3 cos(20) - r3 cos(theta[4] - 30) - 7 cos(theta[4]) - 2}, 

   {r3, theta[4]})

> fsolve({expr1,expr2}, {r3,theta[4]},complex);

           {r3 = -1.079760149 - 6.303261280 I, 

             theta[4] = -10.56469186 + 1.535573576 I}

> solve({(r2*cos(theta[2]) - r3*cos(theta[3])-r4*cos(theta[4])-r1),
> (r2*sin(theta[2])-r3*sin(theta[3])-r4*sin(theta[4]))},Explicit,AllSolutions):

> evalf(%);

{r3 = -1.07976015 + 6.303261286 I, 

  theta[4] = (8.284864050 - 1.535573567 I) + 6.283185308 _Z1}, {

  r3 = -1.07976015 - 6.303261286 I, 

  theta[4] = (8.284864050 + 1.535573567 I) + 6.283185308 _Z1}

When fsolve returns unevaluated (ie, just like you called it, without a numeric result) then it means that it didn't happen to find a numeric approximate solution. You can pass fsolve its `complex` option to allow it to use nonreals.

You can also try to visualize it by plotting expr1 and expr2 and looking at the intersection of those two surfaces. The curve of their intersection does not appear to cross the level plane at height z=0.

You forgot the factor of 0.5 for the cos term when you formed P2 and P3.

f:=proc()
local T,K;
  T:=Matrix(4,4);
  K:=Matrix(6,6);
end proc:
> ee:=itail*(exp(vd/Vth)-1)/(1+exp(vd/Vth)):

> s:=vd/Vth=2*Q:
> ff:=algsubs(s,ee):
> subs(isolate(s,Q),simplify(convert(simplify(expand(convert(ff,trigh))),tanh)));

                                 / vd  \
                       itail tanh|-----|
                                 \2 Vth/

Given the defn

> FunctionAdvisor(tanh,"definition");

     [                  2                                 ]
     [          (exp(z))  - 1                             ]
     [tanh(z) = -------------, with no restrictions on (z)]
     [                  2                                 ]
     [          (exp(z))  + 1                             ]

I might have hoped that convert(ff,tanh) would get it more directly. But

> convert(ff,tanh);

                      itail (exp(2 Q) - 1)
                      --------------------
                          1 + exp(2 Q)    

My question is, does Mathematica's ListPlot command automatically interpolate the smoothed curve as nicely as was shown, and if so how (without being given a candidate curve)? Oh, maybe it doesn't, unless its 'InterpolationOrder' option is provided.

restart:

with(LinearAlgebra):with(CurveFitting):with(Statistics):

t:=RandomVector(20,generator=0.0..2*Pi):
y:=sin~(t)+.5*cos~(t)+RandomVector(20,generator=0.0..0.01):
data:=<t|y>:
P1:=plot(data,style=point,legend="raw points"):

sorted:=Matrix(sort(convert(data,listlist))):
P2:=plot(BSplineCurve(sorted[..,1],sorted[..,2],x,order=3),
         color=green,legend="BSplineCurve"):
P3:=plot(Fit(A*sin(B*x+C),sorted[..,1],sorted[..,2],x),
         x=sorted[1,1]..sorted[-1,1],color=black,legend="Statistics:-Fit"):
new:=sort(RandomVector(200,generator=min(t)..max(t))):
P4:=plot(<new|ArrayInterpolation(sorted,new,method=cubic)>,
         color=blue,legend="ArrayInterpolation"):

plots:-display([P1,P2,P3,P4]);

 

 

How about this?

> restart:

> eqn:= (r,theta) -> BesselJ(0,5*r)*sin(r)*theta;
(r, theta) -> BesselJ(0, 5 r) sin(r) theta

> myInt:=Int(eqn(r, theta), r = 0 .. 5);
                /5                                
               |                                  
               |   BesselJ(0, 5 r) sin(r) theta dr
               |                                  
              /0                                  

> evalf(myInt);
              /5.                                  
             |                                     
             |    BesselJ(0., 5. r) sin(r) theta dr
             |                                     
            /0.                                    

> expand(myInt);
                   /  /5                          \
                   | |                            |
             theta | |   BesselJ(0, 5 r) sin(r) dr|
                   | |                            |
                   \/0                            /

> evalf(expand(myInt));
                    0.026863735681452 theta

> myInt:=T->Int(eqn(r, theta), r = 0 .. T);
       /T                 
      |                   
T ->  |   eqn(r, theta) dr
      |                   
     /0                   

> evalf(myInt(2.0));
              /2.0                                  
             |                                      
             |     BesselJ(0., 5. r) sin(r) theta dr
             |                                      
            /0.                                     

> (evalf@expand)(myInt(2.0));
                      0.01691575057 theta

This shows an opportunity for a great new example for the Online Help page which gets linked to by the magenta error message in the Document.

A do-loop in a Document has to be in a single (execution) Document Block. But without semicolon or colon statement separators after all (but the last) the statements inside the loop body the 2D parser interprets them as being implicit multiplication.

Ie. in this example it parses the statements as if they were

irem(x,7)*x := iquo(x,7)

and so generates the error while trying to assign to irem(x,7)*x.

With such a new example, anyone in this situation who clicked on that error message could get the explanation.

I'll submit an SCR.

You wrote "cotg". Is that just a typo for cot?

This might provide some solutions to part B (and A would be similar), if I haven't done something silly. But the result may depend on some conditions.

A:= (mu^2)*(phi^2)*(1-nu^2)*(cot(alpha2))^2+2*mu*nu*phi*lambda*(cot(alpha2))
      -lambda^2-2*(1-r)*lambda+(mu^2-1)*phi^2=0: B:=phi^2*(1-nu^2)*(cot(alpha3))^2+2*phi*lambda*(cot(alpha3))+lambda^2-2*(1-r)*lambda*nu^2
     +(mu^2-1)*phi^2*nu^2=0: C:=(1-nu^2)*(mu*phi*(cot(beta2))+nu)^2+2*nu*lambda*(phi*mu*(cot(beta2))+nu)
     -lambda^2-2*(1-r)*lambda+(mu^2-1)*phi^2=0: E:=(1-nu^2)*(phi*(cot(beta3))+1)^2+2*lambda*(phi*(cot(beta3))+1)+lambda^2-2*(1-r)*lambda*nu^2
     +(mu^2-1)*phi^2*nu^2=0: rawB:=eliminate(algsubs(cot(alpha2)=C2+cot(beta2),[A,B,C,E]),C2): solB:={seq(subs(C2=cot(alpha2)-cot(beta2),x[1][1]),x in rawB)};

Now, is it the case that the two candidate answers in solB (as returned from above) only hold under conditions such as these:

conditions:=simplify(eval(algsubs(cot(alpha2)=C2+cot(beta2),{A,B,C,E}),rawB[1][1][1])) minus {0=0};
nops(%);

Or have I done something wrong?

You may have various issues related to the confusing or wrong use of operators versus expressions.

But another serious problem is that Bet(k,m) is defined as an equation, with an `=` symbol. But then you've used it inside the defn of `frontint` as if it were some scalar quantity. Did you intend instead to use just the RHS or the LHS of that Bet equation?

I notice also that the defn of B(k,m) uses the symbol lambda (pretty printed). But that name is also being used for the assignment lambda(k,m):=stuff. You've have to resolve that contradiction. Did you really mean to use lambda^2 inside the defn of B(k,m)? Did you instead mean lambda(k,m)^2, or did you want some other variable altogether?

If you resolve those two problems, then we might move on to the issues relating to how you create all your operators (function defns), and whether that is being done back-to-front or whatever.

I often have that problem within Documents, but never within Worksheets. Have you considered switching from Documents to Worksheets?

The square brackets in the expression assigned to frontint are inappropriate. Square brackets are for lists. They don't belong around one of the multiplicands of your integrand. If you just want to block off (delimit) some code to enforce precedence of some operations then use round brackets instead.

Square brackets also appear again inappropriately in the inner term of the double summation assigned to ut(k,m).

Also, please consider either posting your code inlined here as 1D Maple notation input (best) or attached in an uploaded worksheet (green up-arrow button in the editor).

You can also use exports of the plottools package to rotate and reflect a given plot.

P:=plot(sin(x/10),x=0..70):
plottools:-reflect(plottools:-rotate(P,Pi/2),[[0,0],[0,1]]);

See also here.

This would make a good FAQ topic.

First 25 26 27 28 29 30 31 Last Page 27 of 48