acer

32313 Reputation

29 Badges

19 years, 310 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

It seems most likely (to me) the the request is how to assign entries to a Matrix which already exists. Hopefully the submitter will clarify, if needed.

M := Matrix(10,10):
for i from 1 to 10 do
  for j from 1 to 10 do
     M[i,j] := Xlocal(i,j);
  end do;
end do;
M;

The above looping is ok. But really the answer depends on what form your Xlocal is in. If Xlocal is a list of lists or a Maple table (with the right sort of indices) already then you could just pass it directly to the Matrix() constructor. Eg,

Xlocal := [[1,3],[5,7]]:
Matrix(Xlocal);
Xlocal := table([(1,2)=17,(3,2)=11,(3,3)=13]):
Matrix(3,3,Xlocal);

If Xlocal is a procedure, then you could pass it to the Matrix() constructor as the initializer. Eg,

Xlocal := (i,j) -> i*sin(i+j):
Matrix(3,3,Xlocal);

acer

The B is typesetting of Beta. See the help-page for that special function by issuing the command ?Beta.

ps. Do not try define functions in Maple in this way,

f(x):=(1-x^(3/(2)))^(2/(3));

What that actually does is assign to f as if it had a remember table. It may not always behave as you expect. It actually does this,

> f(x):=(1-x^(3/(2)))^(2/(3));
                                         (3/2) (2/3)
                           f(x) := (1 - x     )
 
> eval(f);
               proc() option remember; 'procname(args)' end proc
 
> op(4,eval(f));
                                         (3/2) (2/3)
                        table([x = (1 - x     )     ])

To instead assign f as an expression, do it like this,

f:=(1-x^(3/(2)))^(2/(3));

eval(f, x=1/2); # evaluate at a point

Or, to assign f as a procedure (function) do it like this,

f:= x -> (1-x^(3/(2)))^(2/(3));

f(1/2); # evaluate at a point

acer

I suspect that the point of the exercise is to show that you can compute that more easily by going (temporarily) through polar forms.

Suppose that you have two complex numbers a and b. It can be awkward to raise those to high powers by hand. But if you first convert to polar form, then you can combine the radii and the angles more "easily", and then convert back. Notice how, below, one doesn't have to compute a^12 or b^11 by fully expanding out the complex numbers.

> a := 2-5*I:
> b := 4+I:
> abs(a)^12, 12*argument(a);
                          594823321, -12 arctan(5/2)
 
> abs(b)^11, 11*argument(b);
                                   1/2
                         1419857 17   , 11 arctan(1/4)
 
> rationalize( abs(a)^12 / abs(b)^11 );
                                            1/2
                                594823321 17
                                ---------------
                                   24137569
 
> simplify( arctan( tan(12*argument(a)-11*argument(b)) ) );
                                   3326168023240553
                           -arctan(----------------)
                                   1030781181093988

I'll leave it to you to see how best to convert back to rectangular complex coordinates. Of course, Maple can do it for you either way, easily.

> a^12/b^11;
                    -1030781181093988   3326168023240553
                    ----------------- + ---------------- I
                     34271896307633      34271896307633

> r,theta := op(convert(%,polar));
                                  1/2
                      594823321 17             3326168023240553
          r, theta := ---------------, -arctan(----------------) + Pi
                         24137569              1030781181093988

> r*cos(theta)+I*r*sin(theta);
                    -1030781181093988   3326168023240553
                    ----------------- + ---------------- I
                     34271896307633      34271896307633

acer

> L := [1,2,3,4,5]:
> Statistics:-Mean(L);
                                      3.

> L := Vector[row]([1,2,3,4,5]):
> Statistics:-Mean(L);
                                      3.

> kernelopts(version);
           Maple 11.00, IBM INTEL LINUX, Feb 16 2007 Build ID 277223

acer

By default only small Matrices/Vectors/Arrays are printed in full. Those objects are examples of the rtable data structure in Maple.

The default value at which the behaviour changes from a full elementwise view to the brief view varies with the choice of Maple user interface. I believe that in the Standard GUI the default is that it changes at size 10, and in the commandline interface it changes at size 25.

One can change the interface setting for rtablesize, which specifies the value at which the view switches. (See the ?interface help-page.)

For example,

> interface(rtablesize=3):
> Vector[row]([1,2,3,4,5]);
                           [ 5 Element Row Vector ]
                           [ Data Type: anything  ]
                           [ Storage: rectangular ]
                           [ Order: Fortran_order ]
 
> interface(rtablesize=50):
> Vector[row]([1,2,3,4,5]);
                                [1, 2, 3, 4, 5]

acer

This way, it does not assign to y.

> eq1:=x+y=2:
> isolate(eq1,y):

> eval( s=z+y, % );
                                 s = z + 2 - x
 
> y;
                                       y

acer

Have a look at the help-page ?Optimization,LPSolveMatrixForm

acer

Firstly, did you mean a*x^2+b*c+c, or perhaps a*x^2+b*x+c? (Below, I'm assuming the latter. That makes the equations linear in a,b,c.)

Those conditions won't hold exactly for any d,e,f,g and x0,x1. You can do things like this in Maple, to discover such restrictions,

> P := x -> a*x^2+b*x+c:
> eq1 := P(x0)=d:
> eq2 := D(P)(x0)=e:
> eq3 := P(x1)=f:
> eq4 := D(P)(x1)=g:
> solve({eq1,eq2,eq3,eq4},{a,b,c,x0,x1});

which gives,

{a = 1/4*(e^2-g^2)/(-f+d), b = 1/2*(-x1*e^2-2*g*f+2*g*d+x1*g^2)/(-f+d),
c = 1/4*(x1^2*e^2+4*f*d+4*f*x1*g-4*d*x1*g-4*f^2-x1^2*g^2)/(-f+d),
x0 = (x1*e-2*f+2*d+x1*g)/(e+g), x1 = x1}

But that's to make the equations hold exactly. (Notice the dependence of x0 on d,e,f,g,x1. It is not "free".) The title of your post suggests that you might be looking for something else, however.

Do you want to to know a method to find a,b,c which minimizes some total of squares of residuals (least squares), for given numeric d,e,f,g and x0,x1? If so, you might consider applying LinearAlgebra:-LeastSquares something like this,

> A,B := LinearAlgebra:-GenerateMatrix({eq1,eq2,eq3,eq4},[a,b,c]);
                                [2 x0    1     0]
                                [               ]  [e]
                                [2 x1    1     0]  [ ]
                                [               ]  [g]
                        A, B := [  2            ], [ ]
                                [x0      x0    1]  [d]
                                [               ]  [ ]
                                [  2            ]  [f]
                                [x1      x1    1]

Notice that the above is a matrix form of the equation. Multiplying out the equivalent matrix form shows that's so.

> A . <a,b,c> - B;
                            [   2 a x0 + b - e   ]
                            [                    ]
                            [   2 a x1 + b - g   ]
                            [                    ]
                            [    2               ]
                            [a x0  + b x0 + c - d]
                            [                    ]
                            [    2               ]
                            [a x1  + b x1 + c - f]
> sol := LinearAlgebra:-LeastSquares(eval(A,[e=0.1,g=0.2,d=0.3,f=0.4,x0=1,x1=2]),
>   eval(B,[e=0.1,g=0.2,d=0.3,f=0.4,x0=1,x1=2]));
                               [0.0499999999999999681 ]
                               [                      ]
                        sol := [-0.0099999999999998129]
                               [                      ]
                               [ 0.239999999999999797 ]

I chose some specific numeric values of d,e,f,g,x0,x1 at which to evaluate A and B in doing the above LeastSquares call. The entries of sol are the computed values for a,b,c.

Now evaluate the equations at those same supplied data points.

> eval({eq1,eq2,eq3,eq4},[e=0.1,g=0.2,d=0.3,f=0.4,x0=1,x1=2]);
     {2 a + b = 0.1, 4 a + b = 0.2, a + b + c = 0.3, 4 a + 2 b + c = 0.4}

Now evaluate the last by the least squares solution, to see how well it fits.

> eval(%,{a=sol[1],b=sol[2],c=sol[3]});
{0.09000000000 = 0.1, 0.1900000000 = 0.2, 0.2800000000 = 0.3,
 
    0.4200000000 = 0.4}

What's being done above is this: for given numeric d,e,f,g and x0,x1 it finds the a,b,c which minimizes error in eq1,eq2,eq3,eq4 by least squares. Or at least, that was my intention. There are other commands in Maple which will do something like the steps above, and which can even quantify the calculated least squares error. But it seemed to me that you were wondering how to set it up by hand (for which it is the creation of A,B above that is key.)

acer

Please phrase your post in the form of a question.

acer

> expr := -sin(Pi*(alpha+n+beta))*sin(Pi*beta)/
>         (sin(Pi*(alpha+beta))*sin(Pi*(-1+n+beta)));
                        sin(Pi (alpha + n + beta)) sin(Pi beta)
           expr := - ----------------------------------------------
                     sin(Pi (alpha + beta)) sin(Pi (-1 + n + beta))


> simplify(expand(expr)) assuming
>    alpha::real,alpha>0,beta::real,beta>0,n::posint;
                                       1

acer

You probably intended to get the functionality of signum instead of sign.

I'm referring to your code line,

while sign(f(b)) <> sign(f(c)) do

You might want to look at the respective help-pages ?signum and ?sign.

acer

My guess is that your procedure OVLM is using `i` and assuming that it is unassigned and free, but without having actually declared it as a local variable. That's just a guess.

As Axel says, without an example (or more details) it's almost impossible to gauge what's going on. You've described OVLM's task, but you haven't said anything about how it goes about that.

acer

> equ:=a^2=b^2+c^2;
                                      2    2    2
                              equ := a  = b  + c
 
> eval( equ, [b=1,c=2] );
                                     2
                                    a  = 5
 
> eval( equ, [b=1.,c=2.] );
                                     2
                                    a  = 5.
 
> eval( equ, [b=1/3.,c=1/2.] );
                                2
                               a  = 0.3611111111

acer

It looks like the problem is that the solid lines and the point-plots are not really paired. They are merely overlaid. So the symbols and the lines don't get grouped in the legend.

Done your original way, the legend has only the line, and not the symbols.

If you do it this way next below, then the legend has only the symbols and not the lines.

with(plots):
display(
plot([seq([i,sin(i)],i=1..10)],
     symbol=asterisk,style=point,color=red,
     legend=[typeset(" acc(",`&Hscr;`[1]^`(24)`, ")")]),
plot([seq([i,sin(2*i)],i=1..10)],
     symbol=diamond,style=point,color=green,
     legend=[typeset(" acc(",`ε`[48]^`(1)`, ")")]),
plot([sin(x),sin(2*x)],x=0..10)
);

The following is also not satisfactory, as there is no way to back-up the symbols in the legend. Unfortunately Maple's typesetting doesn't have any mechanism to shift-left (like LaTeX does have), as far as I know.

with(plottools): with(plots):
plots:-display(
seq( point([i,sin(i)], color="red", symbol=asterisk, symbolsize=10), i=1..20),
seq( point([i,sin(2*i)], color="green", symbol=diamond, symbolsize=10), i=1..20),
     plot([sin(x),sin(2*x)],x=0..20,
          legend=[
                  typeset(`&ast;`," acc(",`&Hscr;`[1]^`(24)`, ")"),
                  typeset(`♦`," acc(",`ε`[48]^`(1)`, ")")
                 ]
                  ));

I also couldn't seem to put color on the symbols in that second example above. If I tried to use `#mo("&ast;",mathcolor = "red")` instead of `&ast;` then my Maple 12 GUI froze solid.

Apart from that GUI crash, it would be nice to have a "negative space" availiable in the typesetting. It would also be nice to be able to specify the plot option symbol= where value can be any typeset object and not just one of the named choices.

acer

> f:=x->0.5*x^4-3*x^3-x^2+x+10:
> g:=x->x*exp(1)^(0.5*x-1):

> sol1 := fsolve(f(x)-g(x),x=-20..20);
                              sol1 := 1.528541752
 
> sol2 := fsolve(f(x)-g(x),x=-20..20,avoid={x=sol1});
                              sol2 := 16.51585692
 
> sol3 := fsolve(f(x)-g(x),x=-20..20,avoid={x=sol1,x=sol2});
                              sol3 := 6.650030266

> RootFinding:-Analytic(f(x)-g(x),x=-20-1*I..20+1*I);
             1.52854175180261, 6.65003026642525, 16.5158569246140

acer

First 302 303 304 305 306 307 308 Last Page 304 of 336