pagan

5147 Reputation

23 Badges

17 years, 124 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

How big is your Matrix, that your current approach is not fast enough?

One potential problem with a double-loop approach is in how the solution gets built up. The second method below builds up the solution in a table (a great structure, when you don't know the size of the final object or collection beforehand). The third solution builds up the solution in the classic bad manner of repeatedly concatenating lists.

> N:=150:
> M:=LinearAlgebra:-RandomMatrix(N,generator=0..1):

> st:=time():
> sol1:=[seq(seq(`if`(M[i,j]=1,[i,j],NULL),j=1..N),i=1..N)]:
> time()-st;

                             0.031

> st:=time():
> S:='S':
> for i from 1 to N do
>   for j from 1 to N do
>     if M[i,j]=1 then S[i,j]:=[i,j]; end if;
>   end do;
> end do:
> sol2:=[entries(S,nolist)]:
> time()-st;

                             0.031

> st:=time():
> S:=[]:
> for i from 1 to N do
>   for j from 1 to N do
>     if M[i,j]=1 then S:=[op(S),[i,j]]; end if;
>  end do;
> end do:
> sol3:=S:
> time()-st;

                             6.131

> evalb(sort(sol1)=sort(sol2));

                              true

> evalb(sort(sol1)=sort(sol3));

                              true

The instructor actually tells you the constant function, for part 1). It is the function of x that equals y = f(x) = 1 which is the constant value of 1 for any given input x.

The point of part 1) is for you to justify or explain why f(x)=1 is a better choice than f(x)=2 (or any other constant, for that matter) for approximating f(x)=exp(x) near x=0.

What is the value of exp(x) at x=0?

Later on in the exercise you'll be looking for some possibly non-constant approximation f(x) to exp(x) near x=0. That means for values of x close by 0 you would want f(x) to be close to exp(x). That's what it means to be an approximating function: to be close.

Now, how close do you think f(x) should be right at x=0? Do you think they should match, your f(x) and exp(x), at that particular value of x=0? Why? Could they be closer, at x=0, than an exact match? If that's true for the ideal approximating function, then should it also be true for the crudest possible kind of approximating function (ie. a constant function)?

This is an ugly apporach.

> restart:

> eq:=y=(sin@@3)(0.5143600172e-2+1.000000039*arcsin(arcsin(sin(sin(-0.1543083839e-1
> +.9999999610*RootOf((sin@@3)(_Z)-(sin@@3)(0.5143619410e-2
> +1.000000000*RootOf(-(sin@@3)(_Z)+x)))))))):

> neq:=subsindets(convert(eq,rational,exact),
> specfunc(anything,sin@@3),t->sin(sin(sin(op(t))))):

> nneq:=map(arcsin,map(arcsin,map(arcsin,neq))):
> S:=[allvalues(nneq)]:
> SS:=solve(S[1],x):

> #indets(SS,`local`);
> #Q:=eval(SS,[_B1=0,_B2=0,_B3=0,_B4=0,_B5=0,_B6=0,_Z1=0,_Z2=0,_Z3=0,_Z4=0,_Z5=0,_Z6=0]);
> Q:=subsindets(SS,`local`,t->0);

/ / / 514361941 / / / /
sin|sin|sin|- ------------ + arcsin|arcsin|sin|sin|
\ \ \ 100000000000 \ \ \ \

1028723881980269721
--------------------
99999999999999847900

1000000000000000000 \\\\\\\
+ ------------------- arcsin(arcsin(arcsin(y)))|||||||
999999999999998479 ///////

> #plot(Q,y=-1..1);
> #plot(rhs(eq),x=-1..1,numpoints=5);

> Digits:=100:
> eval(Q,y=.4);
> evalf(eval(rhs(eq),x=%));

0.4038785743862827565501425755766265241552291630481897241421198879810763219042713183329880614372212810

> evalf(eval(rhs(eq),x=%));

0.3999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

You probably want exp(z) not exp^(z) throughout your definition of B.

In 1D Maple notation, the base of the natural logarithm is exp(1), not e which is just another name.

No, for a GUI "Table" alone there is not.

You'd have to manually insert some Component into the cell, and then you could query that with code.

(It's possible for a spreadsheet, by as you know that doesn't offer the same sort of layout options: nesting, suppressed boundary lines, etc.)

> StringTools:-FormatTime("%c");

                   "Fri Mar 04 14:08:13 2011"

See ?FormatTime for more options on the format.

What operating system is your Maple running on?

On Windows 7, I had success with this

Y:=ssystem("dir C:"):
YY:=StringTools:-Drop(Y[2],StringTools:-Search("Serial Number",Y[2])-1):
StringTools:-Take(YY,18+StringTools:-Search("\n",YY[18..-1]));

Do you mean this kind of thing?

P1:=1+Q1^2:
P2:=5-Q2^2:

plot3d([[0,Q2,P2],[Q1,0,P1]],Q1=-1..1,Q2=-1..1,axes=box);

Each of the two curves can be done like the third calling-sequence on the ?plot3d help page, for parametric plots. And since there are two such surfaces/curves, I put both inside another set of square brackets.

Are you using 2D Math input in a version of Maple earlier than 14? In Maple 13 or 12 that if-statement as you wrote it will produce an error message like, "invalid arrow procedure".

You can fix that by using proc(k,j) ... end proc instead of (k,j)->... syntax. Or you can fix it by using the prefix operator `if`. Eg,

p:=(k,j)->`if`(k = 0, max(k-j*S, 0), g[k, j]);

It's not clear whether you want g[k,j] as indexed in which case it could appear with subscripts, or as another function call in which case it could be given as g(k,j).

This may not be what you really wanted, as the factor of cos(k*theta) is introduced by hand.

> r := 1/2 * exp(I*k*theta - 1/2*k^2*sigma^2)* sigma*sqrt(2*Pi)
     + 1/2 * exp(-I*k*theta - 1/2*k^2*sigma^2)* sigma*sqrt(2*Pi);

   1    /            1  2      2\        (1/2)   (1/2)
   - exp|I k theta - - k  sigma | sigma 2      Pi     
   2    \            2          /                     

        1    /             1  2      2\        (1/2)   (1/2)
      + - exp|-I k theta - - k  sigma | sigma 2      Pi     
        2    \             2          /                     

> cos(k*theta)*convert(r/cos(k*theta),exp);

                          (1/2)   (1/2)    /  1  2      2\
      cos(k theta) sigma 2      Pi      exp|- - k  sigma |
                                           \  2          /

You can force that `sum` output into shape

> z:=(s^2+2)*s/(1+s^4+3*s^2);

/ 2 \
\s + 2/ s
-------------
4 2
1 + s + 3 s
> inttrans[invlaplace](z,s,t); ----- \ 1 ) / 2 \ -- / \_alpha + 4/ exp(_alpha t) 10 ----- / 4 2\ _alpha = RootOf\1 + _Z + 3 _Z / > expand(simplify(allvalues(%))); /1 (1/2)\ /1 \ 1 (1/2) /1 (1/2)\ /1 \ cos|- t 5 | cos|- t| + - 5 sin|- t 5 | sin|- t| \2 / \2 / 5 \2 / \2 /

And for factoring, FWIW


> convert(evala(Factor(denom(z),RootOf(_Z^2-5))),radical);

/ 2 3 1 (1/2)\ / 2 3 1 (1/2)\
|s + - + - 5 | |s + - - - 5 |
\ 2 2 / \ 2 2 /

> KS:=[solve(denom(z),Explicit=false)];

[ / / 2 \ 2\]
[RootOf\-RootOf\1 + _Z + 3 _Z/ + _Z /]

> convert(evala(Factor(denom(z),op(KS[1]))),radical);

/ 2 3 1 (1/2)\ / 2 3 1 (1/2)\
|s + - + - 5 | |s + - - - 5 |
\ 2 2 / \ 2 2 /

> convert(evala(Factor(denom(z),KS[1])),radical);

/
/ 1 (1/2) 1 \ / 1 (1/2) 1 \ |
|s + - I 5 - - I| |s - - I 5 + - I| |s
\ 2 2 / \ 2 2 / \

(3/2) \ /
/1 (1/2) 3\ 3 (1/2) 3 | |
+ |- 5 - -| + - I 5 - - I| |s
\2 2/ 2 2 / \

(3/2) \
/1 (1/2) 3\ 3 (1/2) 3 |
- |- 5 - -| - - I 5 + - I|
\2 2/ 2 2 /

You may be able to get mileage out of type,satisfies

> define(g, g(x::satisfies(t->is(t,realcons)))=x );

> g(y);

                              g(y)

> assume(a::realcons);

> g(a);
                               a~

Coding it by hand (just an example, improvements possible)

> restart:

> g:=proc()
>    if _npassed=1 and is(args[1],realcons) then
>       return args[1];
>    else
>       return 'procname'(_passed);
>    end if;
> end proc:

> g(a);

                              g(a)

> assume(a::realcons);

> g(a);
                               a~

You could compute all the eigenvalues, sort them, grab the "largest", use that eigenvalue for lambda in the characteristic matrix, and then compute the nullspace (kernel) of that.

Is your Matrix entirely floating-point data? Would hardware double-precision results suffice? Unless done very carefully, there's a chance that an implementation of the above nullspace approach might run slower than simply computing all eigenvectors and selecting just those that correspond to the largest eigenvalue.

If that's too slow, you can find 3rd party (C or Fortran) code which does this task, and compile and external-call it from Maple.

Use s:=s+1 not s=s+1 in order to make an assignment to s.

Also, you have to compare an element of A to 70, not A itself. For example, if L had 1000 indexable entries

counter:=0:
for i from 1 to 1000 do
   if L[i]=70 then
      counter:=counter+1;
   end if;
end do:
counter;

There are more sophisticated ways, and shorter ways to code it. But that might help you along.

First 17 18 19 20 21 22 23 Last Page 19 of 48