acer

20133 Reputation

29 Badges

14 years, 359 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Put your followup queries on this topic as comments here in this same thread, please.

Please upload .mw worksheets (green up arrow in the Mapleprimes editor) since you're having copy and paste issues. (And never paste in 2D input code as plaintext here.)

@Christopher2222 Actually you should describe your actual background problem up front.

@rquirt Units:-Simple allows you to add blah*Unit(W) and the unevaluated function call to your proc (which itself returns a quantity with units).

I removed the call to `with(Units:-Standard)` at the top level. The procedure revision i gave works without it. I utilized `uses` in the proc instead. (It is not great programming to write a proc that only works if `with`is called outside it.)

I also made your proc return unevaluated when the first argument is not numeric*unit or numeric.

There was also a left- right- quote match typo in your original.

Better to upload actual working code or worksheet. 

@MAJP Firstly, I commend you for putting in real effort at solving this. It's refreshing to see.

I suspect that you have made two or three typo's in writing down the formula for Fdiff[i].

The first is that you are missing a multiplication sign between two pairs of round brackets. So that ends up being parsed as function application rather than multiplication. (Maple allows you to apply a floating-point number to something else, and it returns that same float.)

The second seems to be that you have (F[i]-1) instead of (F[i]+1) in the formula for Fdiff[i].

Also, as Carl mentioned, you have an y[1] which ought to be y[i] in the formula for dAdy[i].

If I make those adjustments then the derivative of F appears to match Fdiff. And then the starting point y0=1 allows convergence to the root near y=2.4222.

In order to get convergence to the apparent root near y=-8.57 I wrapped the formula for y[i+1] with two commands whose purpose is to remove any small imaginary component (where small means close to the working precision.) You can get rid of that if you find it's out of scope for your task.

I suppose you realize that you don't really need to keep track of all the values of A,P,Fdiff,etc for all i values. You could just as well use non-indexed names for those. The indexing of Y is key to your approach, of course.

restart;

Newton := proc (n, y0, Q, b, m, k, S0)
  local A, P, Sf, y, F, dAdy, dPdy, Fdiff, i, ylist;
  y[0] := evalf(y0);
  for i from 0 to n do
    A[i] := (b+m*y[i])*y[i];
    P[i] := evalf(b+2*y[i]*sqrt(1+m^2));
    Sf[i] := evalf(Q*abs(Q)*P[i]^(4/3)/(k^2*A[i]^(10/3)));
    F[i] := S0/Sf[i]-1;
    dAdy[i] := b+2*m*y[i];
    dPdy[i] := evalf(2*sqrt(1+m^2));

    #Fdiff[i] := -(4/3)*S0*k^2*A[i]^(10/3)*(dPdy[i])/(Q*abs(Q)*P[i]^(7/3))
    #            +(10/3)*S0*k^2*A[i]^(7/3)*(dAdy[i])/(Q*abs(Q)*P[i]^(4/3));
    Fdiff[i] := (2/3)*(F[i]+1)*(5*dAdy[i]/A[i]-2*dPdy[i]/P[i]);

    y[i+1] := simplify( fnormal( y[i]-F[i]/Fdiff[i] ), ':-zero' );
  end do;

  ylist := [seq(y[i], i = 0 .. n)];
  return ylist
end proc:

 

Newton(10, 1, 5, 12, 1, 30, 10^(-5));

[1., 6.573224507, 4.850242691, 3.616575701, 2.840981033, 2.493303585, 2.424667056, 2.422212016, 2.422208959, 2.422208959, 2.422208959]

Newton(10, -8, 5, 12, 1, 30, 10^(-5));

[-8., -8.487501254, -8.568487419, -8.570502786, -8.570504010, -8.570504009, -8.570504009, -8.570504009, -8.570504009, -8.570504009, -8.570504009]

ee := S0/(Q*abs(Q)*P(y)^(4/3)/(k^2*A(y)^(10/3)))-1;

S0*k^2*A(y)^(10/3)/(Q*abs(Q)*P(y)^(4/3))-1

dee := diff(ee,y);

-(4/3)*S0*k^2*A(y)^(10/3)*(diff(P(y), y))/(Q*abs(Q)*P(y)^(7/3))+(10/3)*S0*k^2*A(y)^(7/3)*(diff(A(y), y))/(Q*abs(Q)*P(y)^(4/3))

hdee := (2/3)*(ee+1)*(5*diff(A(y),y)/A(y)-2*diff(P(y),y)/P(y));

(2/3)*S0*k^2*A(y)^(10/3)*(5*(diff(A(y), y))/A(y)-2*(diff(P(y), y))/P(y))/(Q*abs(Q)*P(y)^(4/3))

simplify( hdee -dee );

0

this := eval(eval(ee, [A(y)=(b+m*y)*y,
                  P(y)=b+2*y*sqrt(1+m^2)]),
             [Q=5, k=30, S0=10^(-5), m=1, b=12]);

(9/25000)*((y+12)*y)^(10/3)/(12+2*y*2^(1/2))^(4/3)-1

Digits := 30;

30

sol1 := fsolve(this, y=1..10);

2.42220895913004814986049595028

evalf[100](eval(this, y=sol1)): evalf[10](%);

-0.4597438638e-29

sol2 := fsolve(abs(this), y=-9..-8);

-8.57050400897802308341902137162

evalf[100](eval(this, y=sol2)): evalf[10](%);

-0.3528983078e-29-0.9378067234e-100*I

foo := simplify(combine(expand(this)),size) assuming y>-9, y<-8;

-(9/100000)*y^3*(y+12)^3*(-(4*y+48)*y*(6+y*2^(1/2))^2)^(1/3)/(6+y*2^(1/2))^2-1

fsolve(foo, y=-9..-8);

-8.57050400897802308341902137162

bar := eval(ee, [A(y)=(b+m*y)*y,
                  P(y)=b+2*y*sqrt(1+m^2)]);

S0*k^2*((m*y+b)*y)^(10/3)/(Q*abs(Q)*(b+2*y*(m^2+1)^(1/2))^(4/3))-1

bbar := simplify(evalc(bar),size) assuming real, m<b/y, b>=10, b<13, y>-9, y<-7;

S0*k^2*(-m*y^2-b*y)^(10/3)/(Q*abs(Q)*(-b-2*y*(m^2+1)^(1/2))^(4/3))-1

fsolve(eval(bbar, [Q=5, k=30, S0=10^(-5), m=1, b=12]), y=-9..-8);

-8.57050400897802308341902137162

 

Download newtthing.mw

@MAJP Each iteration through the loop , do you want to be defining y[i] in term of the previous value y[i-1] ?

Trying to assign y[i] in terms of a formula with y[i] is not right.

You'll  also need to consider whether the other indexed names in the formulas in the loop should use the current iteration's values indexed by i, or the previous iteration's values indexed by i-1.

I feel sure that, by thinking about this aspect, you'll understand what the iteration is supposed to accomplish.

 

@sand15 

Whenever I install Maple the next thing I do is edit the properties of the launcher, to add (along with a blank space as separator) the option
   -standalone
to the end of the invocation of the GUI executable.

This has the effect that I can launch separate worksheets under separate Java jvm processes. And if one of them stalls or freezes or crashes (in the GUI sense) then the other one(s) stay ok.

It'll even let me open the same worksheet twice.

Memory is cheap. Back around Maple 10 the few hundred MB footprint of the GUI+jvm seemed huge. Now it seems modest.
 

@erdisayar 

The code for the module J is in the Startup Code of this attachment.  (Use the menubar's Edit->Startup Code to see it, or modify it.)  The whole point is that the input is 1D and the pretty-printed names appear in the 2D output.

You can make the commands as long as you wish, or as short as a single character. You could add additional commands like J:-dash which puts a bar over a name, so that you don't have to remember HTML entity names. Or you could add  additional commands like J:-o which puts anything over anything. Or you could could add additional commands like, say. br for bottom-right or tl for top-left.

You can assign the marked up names to any other variable of your choice.

If you really wanted to you could add additional options to allow you to specify the color, boldness, or upright vs italic.

Of course it involves more typing, but you can create your own procedure names for custom mnemonics. If you also utilize use and uses (see examples) then it's not that much more typing than LaTeX.

restart;

 

J:-dash(X);

`#mover(mi("X"),mrow(mi("\`&mdash;\`")))`

 

use J in

  o(A,`&centerdot;`)*I*Pi + arctan(3*o(X,`&minus;`)/sb(Y,3,5));

  Adot := o(A,`&rarr;`);
  Xbar := dash(X);

end use;

I*`#mover(mi("A"),mrow(mi("\`&centerdot;\`")))`*Pi+arctan(3*`#mover(mi("X"),mrow(mi("\`&minus;\`")))`/`#msub(mi("Y"),mrow(mrow(mn("3"),Typesetting:-mo("&comma;"),mn("5"))))`)

`#mover(mi("A"),mrow(mi("\`&rarr;\`")))`

`#mover(mi("X"),mrow(mi("\`&mdash;\`")))`

Adot + Xbar;

`#mover(mi("A"),mrow(mi("\`&rarr;\`")))`+`#mover(mi("X"),mrow(mi("\`&mdash;\`")))`

 

P := proc(t)
  local q,r;
  uses J;

  r := dash(Q);
  return sin(r*t) + int(sb(t,i,j)(y), y=0..Pi);
end proc:

P(x);

Parse:-ConvertTo1D, "invalid input %1", Typesetting:-mprintslash([sin(`#mover(mi("Q"),mrow(mi("\`&mdash;\`")))`*x)+int(`#msub(mi("x"),mrow(mrow(mi("i"),Typesetting:-mo("&comma;"),mi("j"))))`(y), y = 0 .. Pi)], [sin(`#mover(mi("Q"),mrow(mi("\`&mdash;\`")))`*x)+int(`#msub(mi("x"),mrow(mrow(mi("i"),Typesetting:-mo("&comma;"),mi("j"))))`(y), y = 0 .. Pi)])

 

J:-sb(A,6);

`#msub(mi("A"),mrow(mn("6")))`

J:-sb(A,4,3,2);

`#msub(mi("A"),mrow(mrow(mn("4"),Typesetting:-mo("&comma;"),mn("3"),Typesetting:-mo("&comma;"),mn("2"))))`

J:-sp(A,6);
J:-sp(x,`&prime;`);

`#msup(mi("A"),mrow(mn("6")))`

`#msup(mi("x"),mrow(mi("\`&prime;\`")))`

J:-sp(A,4,3,2);

`#msup(mi("A"),mrow(mrow(mn("4"),Typesetting:-mo("&comma;"),mn("3"),Typesetting:-mo("&comma;"),mn("2"))))`

J:-o(A,m);

`#mover(mi("A"),mrow(mi("m")))`

J:-o(A,x,y,z);

`#mover(mi("A"),mrow(mrow(mi("x"),Typesetting:-mo("&comma;"),mi("y"),Typesetting:-mo("&comma;"),mi("z"))))`

J:-o(x,`&minus;`);
J:-o(Z,`&^;`);

`#mover(mi("x"),mrow(mi("\`&minus;\`")))`

`#mover(mi("Z"),mrow(mi("\`&^;\`")))`

J:-u(A,x,y,z);
J:-u(A,`&rarr;`);

`#munder(mi("A"),mrow(mrow(mi("x"),Typesetting:-mo("&comma;"),mi("y"),Typesetting:-mo("&comma;"),mi("z"))))`

`#munder(mi("A"),mrow(mi("\`&rarr;\`")))`

J:-uo(W,`&rarr;`,`&lowast;`);
J:-uo(W,[a,b],[[x,y]]);

`#munderover(mi("W"),mrow(mi("\`&rarr;\`")),mrow(mi("\`&lowast;\`")))`

`#munderover(mi("W"),mrow(mrow(mi("a"),Typesetting:-mo("&comma;"),mi("b"))),mrow(mfenced(mi("x"),mi("y"),open = "&lsqb;",close = "&rsqb;")))`

J:-sc(A,1,2,3,4,5,6);

`#mscripts(mi("A"),mrow(mn("1")),mrow(mn("2")),mrow(mn("3")),mrow(mn("4")),mrow(mn("5")),mrow(mn("6")))`

J:-sc(A,1);
J:-sc(A,1,`&plus;`);
J:-sc(A,1,`&ast;`,3);

`#mscripts(mi("A"),mrow(mn("1")),mrow(none()),mrow(none()),mrow(none()),mrow(none()),mrow(none()))`

`#mscripts(mi("A"),mrow(mn("1")),mrow(mi("\`&plus;\`")),mrow(none()),mrow(none()),mrow(none()),mrow(none()))`

`#mscripts(mi("A"),mrow(mn("1")),mrow(mi("\`&ast;\`")),mrow(mn("3")),mrow(none()),mrow(none()),mrow(none()))`

J:-sc(X,[],[],2);
J:-sc(Y,x,[],[],[],y);
J:-sc(Z,[],a,[],[],[],b);

`#mscripts(mi("X"),mrow(none()),mrow(none()),mrow(mn("2")),mrow(none()),mrow(none()),mrow(none()))`

`#mscripts(mi("Y"),mrow(mi("x")),mrow(none()),mrow(none()),mrow(none()),mrow(mi("y")),mrow(none()))`

`#mscripts(mi("Z"),mrow(none()),mrow(mi("a")),mrow(none()),mrow(none()),mrow(none()),mrow(mi("b")))`

# evaluation sanity check
u,s,t,v,w,A := 'u','s','t','v','w','A':
u:=s: s:=t: t:=v: v:=w: w:=A:
J:-sb('u',6), J:-sb(u,6), J:-sb(eval(u,3),6);

`#msub(mi("u"),mrow(mn("6")))`, `#msub(mi("A"),mrow(mn("6")))`, `#msub(mi("v"),mrow(mn("6")))`

# evaluation sanity check
p,q := [3,4], 5:
J:-sc(A, [1,2], p, q,
           6, 7, 8);
J:-sc(AAAAA, [[1,2]], 'p', 'q',
           6, 7777, 8);

`#mscripts(mi("A"),mrow(mrow(mn("1"),Typesetting:-mo("&comma;"),mn("2"))),mrow(mrow(mn("3"),Typesetting:-mo("&comma;"),mn("4"))),mrow(mn("5")),mrow(mn("6")),mrow(mn("7")),mrow(mn("8")))`

`#mscripts(mi("AAAAA"),mrow(mfenced(mn("1"),mn("2"),open = "&lsqb;",close = "&rsqb;")),mrow(mi("p")),mrow(mi("q")),mrow(mn("6")),mrow(mn("7777")),mrow(mn("8")))`

map(J:-sp@op,
    [[A,`&clubs;`],[K,`&diams;`],
     [Q,`#mi("&hearts;",mathcolor=red)`],
     [J,`#mi("&spades;",mathcolor=black)`],
     [10,`#mi("&diams;",mathcolor=red)`]]);

[`#msup(mi("A"),mrow(mi("\`&clubs;\`")))`, `#msup(mi("K"),mrow(mi("\`&diams;\`")))`, `#msup(mi("Q"),mrow(mi("&hearts;",mathcolor = red,Typesetting:-msemantics = "atomic")))`, `#msup(mi("J"),mrow(mi("&spades;",mathcolor = black,Typesetting:-msemantics = "atomic")))`, `#msup(mn("10"),mrow(mi("&diams;",mathcolor = red,Typesetting:-msemantics = "atomic")))`]

 

Download Mark.mw

@C1Ron 

restart;

f := (a,z) -> z*exp(a*z) / (z^2 + 1)^2:

R:=[singular(f(a,z),z)];

[{z = -I}, {z = I}]

R[1];

{z = -I}

op(R[1]);

z = -I

R[1][];

z = -I

residue(f(a,z), op(R[1]));

((1/4)*I)*a/exp(I*a)

residue(f(a,z), R[1][]);

((1/4)*I)*a/exp(I*a)

seq(residue(f(a,z), op(eq)), eq=R);

((1/4)*I)*a/exp(I*a), -((1/4)*I)*a*exp(I*a)

seq(residue(f(a,z), eq[]), eq=R);

((1/4)*I)*a/exp(I*a), -((1/4)*I)*a*exp(I*a)

 

Download op_examp.mw

Every one of your queries submitted to this site has been a Post. And someone has had to convert each to a Question. I don't think that is very considerate of you.

Could you please use the Question form in future? It's right there at the top right of this site, right beside the Post form.

@erdisayar You mentioned LaTeX, for comparison, which entails a more verbose 1D plaintext form.

That makes it sound as if you are willing to use a 1D plaintext syntax for marking up your symbols/names with immutable subscripts and overscripts. If that's true then I can show you how. But, as input, it will require more typing/keystrokes.

I have always found 2D Input mode to be awkwardly impractical at best, and buggy at worst. I don't know how people manage to use it, even with keyboard shortcuts. It's curious to me that you're still trying to find a way to work with it easily.

I resisted changing everything to my own taste, since I believe that the OP is learning by doing.

Otherwise, a somewhat similar effect could be had with, say,

restart;

F:=proc(u,a,b,c,d)
  local expr, x;
  if u="   y = a sin(b x + c) + d " then
    expr := evalf[3](a*sin(b*x + c) + d);
    plot(expr, x=-2*Pi..2*Pi,
         ':-title'=expr,
         ':-view'=-3 .. 6);
  elif u="   y = sin(a x) + cos(b x) " then
    expr :=  evalf[3](sin(a*x) + cos(b*x));
    plot(expr, x=-2*Pi..2*Pi,
         ':-title'=expr,
         ':-view'=-2..2);
  else error u;
  end if;
end proc:

Explore( F(`function :`,a,b,c,d),
         parameters=[ [`function :`=["   y = a sin(b x + c) + d ",
                                     "   y = sin(a x) + cos(b x) "],
                       #controller="listbox",
                       placement=top]
                    ],
         a = 1.0 .. 3.0, b = 1.0 .. 3.0,
         c = 0.0 .. 2*Pi, d = 0.0 .. 3.0,
         placement = right
         #, newsheet, showbanner=false, startupdefinitions=[F]
       );

Could you upload your data here as an attachment (green up-arrow)?

@Ramakrishnan One of the problems with your original was that MyApp did not export ChangeE. So when you called ChangeE() in the code of the Sliders nothing happened.

If you are interested in using different formulas and radio buttons:  doubt2_MathContainer_ac2.mw

@Ramakrishnan You mean you're posting the same question twice? Please don't do that.

The first thing to clarify is the format of your data. It looks like the three columns denote four points of [x,y,z] data, rather than a 3x4=12 collection of [x,y] data points. Is that right?

What version of Maple are you using?

Is this a toy example, and you plan on wanting to do it for larger sets of points (possibly with surface smoothing)? Or do you just need to deal with this kind of simple 3D polygon with a quadrilateral base?

 

First 69 70 71 72 73 74 75 Last Page 71 of 435