MaplePrimes Questions

Dear all

 

I want to display the value of k   for which the stop test is verified. Thanks for your help. 



epsilon:=(y0,N)->evalf(abs(

 testerror:=array(1..75);
for k from 2 by 2 to 50 do
testerror[k]:=data[RK3][k][2];
if testerror[k]<=0.0001 then break; end if; end do;

i_before_e$.mw

My Homies

I'm trying to find words which contradict the rule "i before e except after c". according to BBC program "QI" there are 923 exceptions, but below i get less than that. i guess its only as good as the dictionary, the 'inbuilt' has only 25k words but 'ospd3' (with 80k words) seems to stop before letter Q (with my sledgehammer code) when there are more words out there like "weird", "veil" and "reciept".

with(StringTools); with(PatternDictionary); bid := Create(ospd3);
words :=([seq])(LowerCase(Get(bid, i)), i = 1 .. Size(bid)-1);
tot := 0;
for n to nops(words) do
C := searchtext(cie, words[n]); E := searchtext(ei, words[n]);
if`and`(C = 0, E = 0) then next else tot := tot+1;
print([tot, words[n]]) end if
end do

Dear collegues

I wrote the following code

 


restart:
Digits := 15;
a[k]:=0;
b[k]:=7.47;
a[mu]:=39.11;
b[mu]:=533.9;
mu[bf]:=9.93/10000;
k[bf]:=0.597;
ro[p]:=3880 ;
ro[bf]:= 998.2;
c[p]:= 773;
c[bf]:= 4182;
#mu[bf]:=1;
Gr[phi]:=0; Gr[T]:=0;
#dp:=0.1;
Ree:=1;
Pr:=1;
Nbt:=cc*NBTT+(1-cc^2)*6;

#######################
slip:=0.1;         ####
NBTT:=2;           ####
lambda:=0.1;       ####
phi_avg:=0.02;    ####
#######################


eq1:=diff( (1+a[mu]*phi(eta)+b[mu]*phi(eta)^2)*diff(u(eta),eta),eta)+dp/mu[bf]+Gr[T]*T(eta)-Gr[phi]*phi(eta);
eq2:=diff((1+a[k]*phi(eta)+b[k]*phi(eta)^2)*diff(T(eta),eta),eta)+lambda*T(eta)/k[bf];
eq3:=diff(phi(eta),eta)+1/Nbt*diff(T(eta),eta);
Q:=proc(pp2,fi0) local res,F0,F1,F2,a,INT0,INT10;
global Q1,Q2;
print(pp2,fi0);
if not type([pp2,fi0],list(numeric)) then return 'procname(_passed)' end if:
res := dsolve({subs(dp=pp2,eq1)=0,eq2=0,eq3=0,u(0)=slip*D(u)(0),u(1)=-slip*D(u)(1),D(T)(0)=0,D(T)(1)=1,phi(0)=fi0}, numeric,output=listprocedure,continuation=cc);
F0,F1,F2:=op(subs(res,[u(eta),phi(eta),T(eta)])):
INT0:=evalf(Int(F0(eta),eta=0..1));
INT10:=evalf(Int(F0(eta)*F1(eta),eta=0..1));
a[1]:=evalf(Int(F0(eta),eta=0..1))-Ree*Pr;;
a[2]:=INT10/INT0-phi_avg;
Q1(_passed):=a[1];
Q2(_passed):=a[2];
if type(procname,indexed) then a[op(procname)] else a[1],a[2] end if
end proc;
Q1:=proc(pp2,fi0) Q[1](_passed) end proc;
Q2:=proc(pp2,fi0) Q[2](_passed) end proc;
Optimization:-LSSolve([Q1,Q2],initialpoint=[0.3,0.0007]);




se:=%[2];
res2 := dsolve({subs(dp=se[1],eq1)=0,eq2=0,eq3=0,u(0)=slip*D(u)(0),u(1)=-slip*D(u)(1),D(T)(0)=0,D(T)(1)=1,phi(0)=se[2]}, numeric,output=listprocedure,continuation=cc);
G0,G1,G2:=op(subs(res2,[u(eta),phi(eta),T(eta)])):
TTb:=evalf(Int(G0(eta)*G2(eta)*(G1(eta)*ro[p]*c[p]+(1-G1(eta))*ro[bf]*c[bf] ),eta=0..1))/evalf(Int(G0(eta)*(G1(eta)*ro[p]*c[p]+(1-G1(eta))*ro[bf]*c[bf] ),eta=0..1));
with(plots):
odeplot(res2,[[eta,phi(eta)/phi_avg]],0..1);
odeplot(res2,[[eta,T(eta)/TTb]],0..1);
odeplot(res2,[[eta,u(eta)/(Ree*Pr)]],0..1);

res2(1);
Nuu:=(1/TTb);
1/((1+a[k]*G1(1)+b[k]*G1(1)^2)/(1+a[k]*phi_avg+b[k]*phi_avg^2));
(1/TTb)*(((1+a[k]*G1(1)+b[k]*G1(1)^2)/(1+a[k]*phi_avg+b[k]*phi_avg^2)));
>

I want to run the code for the value of NBTT in the range of 0.2 to 10. this code gave the results in the range of 4-10 easily. So, I used the continuation which improve the range of the results between 2-10. However, I coudnt gave the results when 0.2<NBTT<2. Would you please help me in this situation.

Also, It is to be said that the values of phi should be positive. in some ranges, I can see that phi(1) is negative. Can I place a condition in which the values phi restricted to be positive.

Thanks for your attentions in advance

Amir

I want to define the budget set of a consumer, which consists of an horizontal, slant and vertical line segments. How can I define and plot the budget set?

I find this a little frustrating as I learn Maple, so I think there is a better way to handle this.

I find myself having to keep wrapping expressions with evalf() in order to compare them, since when I use a constant such as Pi in these expressions and then compare them,  Maple complains.

In a large program, one does not know if an expression contains Pi or not beforehand, so is one really supposed to convert every expression to float just in case they might need to compare 2 expressions? 

Let me explain with simple example:

x:=1.2;  #it does not matter if this was 12/10 or 1.2, same error will result.
y:=Pi/3;
if x<y then
   print("x<y");
else
   print("x>=y");
fi;

The above gives the error "Error, cannot determine if this expression is true or false: 1.2<(1/3)*Pi"

So I changed the y assignment above to y:=evalf(Pi/3); or evalf(Pi)/3; and now Maple is happy.

But this for me looks awkward. In Mathematica, I can simply write the same, using symbolic Pi, and it works as is:

x = 1.2;  #even if this is symbolic 12/10 it will also work
y = Pi/3;
If[x < y, Print["x<y"], Print["x>=y"]]

I did not have to write  y=N[Pi/3]  where N[] is the equivalent function to Maple's evalf() which converts its argument to real.

So, now in Maple, I find myself writing evalf() around so many things, since I have to anticipate I might need to compare them in some logic later on and I can't keep track which one has some symbolic constant such as Pi in them or not. While in Mathematica I never had to worry about this.

Is there a way to reduce the need to having to use evalf() so much?
It seems to me, Maple should be able to decide if  1<Pi without me having to write 1<evalf(Pi) ?

 

I have two equations that are valid under the substitution sin <-> cos, so a simple way to generate the second equation is to replace all occurrences of sin with cos. But Maple gets the wrong answer when I do this, because of its built-in simplification. Here is an example. Z1 and Y1 shows the problem; Z2 and Y2 shows that my attempt to overcome the problem doesn't work.  Z3 doesn't work either, proving that the problem is internally generated by Maple because Maple insists on ordering variables in its own way, no matter how I write them.

________simplified example from Maple 15

restart;
Z1:=sin(-a*x+b);
Z2:='sin(-a*x+b)';
Z3:=sin(b-a*x);



                         -sin(a x - b)
                         sin(-a x + b)
                         -sin(a x - b)
Y1:=subs(sin=cos,Z1);
Y2:=subs(sin=cos,Z2);


                         -cos(a x - b)
                         -cos(a x - b)
 correct answer should be cos(-a*x+b) but the calculated results are off by a minus sign.

Ans1:=evalf(subs(a=1,b=2,x=3,[Y1,Y2,cos(-a*x+b)]));
          [-0.5403023059, -0.5403023059, 0.5403023059]

Question: How do I override Maple's desire to stick the "-" sign outside the sin function?

Dear all;

Than you for help.

how  many steps are required to achieve a error of 1.e-3 in the numerical value of y(1).

Here The 3 -step procedure  Range Kutta Method.

## Exact  solution  

### We will modifty N ( number of steps to get error =10^(-3). )

 

## Procedure Range Kutta

> RK3 := proc (f, a, b, y0, N)

local x, y, n, h, k, vectRK3;

y := Array(0 .. N);

x := Array(0 .. N);

h := evalf(b-a)/N;

x[0] := a; y[0] := 1;

for n from 0 to N-1 do

x[n+1] := a+(n+1)*h;

k[1] := f(x[n], y[n]);

k[2] := f(x[n]+(1/2)*h, y[n]+(1/2)*h*k[1]);

k[3] := f(x[n]+h, y[n]+h*(-k[1]+2*k[2]));

y[n+1] := y[n]+(1/6)*h*(k[1]+4*k[2]+k[3])

end do;

[seq([x[n], y[n]], n = 0 .. N)]; y[1];

end proc;

## Now  we compute the error between y(1) and exact  solution for different value of  N

### I have a problem in this part


 errorRk3 := array(1 .. 29);
 for N from  2 to 30 do

errorrRk3[N] := abs(eval(rhs(res), x = 1)-RK3((x,y)->-y,0,1,N));

if errorrRk3[N] =10^{-3} end ;
end  do ;

 

 

Hi all,

 

Say I have some list like this,

tmp:=[[0, 0, 1], [0, 1, 0], [0, 1, 1], [0, 1, 2], [1, 0, 0], [1, 0, 1], [1, 0, 2], [1, 1, 0], [1, 1, 1], [1, 1, 2], [1, 2, 0]];

 

And I have worked out some probabilities for each of them, a,b,c,d, ect.

I want to print them like this

Pr( 001 ) = 1

Pr( 010 ) = 1-phi[2]+phi[2]*(1-p[3])*(1-phi[3])

Pr( 011 ) = phi[2]*p[3]*(1-phi[3])

and so on.

I there a way to do that?

The probabilities can be extracted from a Vector. I have no problem to print them.

I dont know how to convert the 0,1,2 into the desired format as shown above.

 

This is the best I can do.

 

Also, is it possible to convert all the subscripte [] to _ when printing the output?

and get ride of all * as well.

Thanks,

 

casperyc

 

ali := (1/12)*(12*c[4]*ln(x+1)*x^4+48*c[4]*ln(x+1)*x^3+72*c[4]*ln(x+1)*x^2+48*c[4]*ln(x+1)*x+12*c[1]*x+30*c[2]*x^2+12*c[2]*x+36*c[3]*x^3+36*c[3]*x^2+12*c[3]*x+12*c[5]*x^5+48*c[5]*x^4+72*c[5]*x^3+48*c[5]*x^2+3*c[0]*x^4+12*c[0]*x^3+18*c[0]*x^2+12*c[0]*x+4*c[1]*x^4+16*c[1]*x^3+24*c[1]*x^2+6*c[2]*x^4+24*c[2]*x^3+12*c[3]*x^4+12*c[4]*ln(x+1)+12*c[5]*x)/(x+1)^4+.1

but simplify(ali-simplify(ali)) is not equal to 0!

 

Dear all,

I need your help

I have a problem with dchange ....  use the dchange command to transform pde to the
                                 x[1], x[2].

 

> restart;
> with(PDEtools); with(LinearAlgebra);
> pde := diff(u(t), t, t)+2*GAMMA*(diff(u(t), t))+omega^2*u(t) = 0;
           / d  / d      \\           / d      \        2         
           |--- |--- u(t)|| + 2 GAMMA |--- u(t)| + omega  u(t) = 0
           \ dt \ dt     //           \ dt     /                  
> deq1 := diff(u(t), t) = v(t);
                                d             
                               --- u(t) = v(t)
                                dt            
>
> deq2 := subs(deq1, pde);
                 / d      \                       2         
                 |--- v(t)| + 2 GAMMA v(t) + omega  u(t) = 0
                 \ dt     /                                 
>
> dsolve({deq1, deq2}, {u(t), v(t)});
>
> eqns := [rhs(deq1) = lhs(deq1), rhs(deq2) = lhs(deq2)];
       [        d            / d      \                       2     ]
       [v(t) = --- u(t), 0 = |--- v(t)| + 2 GAMMA v(t) + omega  u(t)]
       [        dt           \ dt     /                             ]
> y := [u, v]; b := diff(y(t), t);
                                   [u, v]
                            [ d         d      ]
                            [--- u(t), --- v(t)]
                            [ dt        dt     ]
> A, b := GenerateMatrix(eqns, y(t));
          Matrix(%id = 122038892), Vector[column](%id = 135944696)
 # Return a vector of eigenvalue of A and matrix  whose columns are eigenvectors of A
> gnat := Eigenvectors(A);
> lambda := gnat[1]; Lambda := gnat[2];
                       Vector[column](%id = 135975976)
                           Matrix(%id = 136787860)
> Y := Vector([y]);
                       Vector[column](%id = 123771808)
> tr := solve(GenerateEquations(Lambda, [x[1], x[2]], Y), {u, v});
     /           /                                    (1/2)             
     |      1    |                   /     2        2\                  
    < u = ------ \-x[1] GAMMA - x[1] \GAMMA  - omega /      - x[2] GAMMA
     |         2                                                        
     \    omega                                                         

                               (1/2)\                 \
              /     2        2\     |                 |
       + x[2] \GAMMA  - omega /     /, v = x[1] + x[2] >
                                                      |
                                                      /
>
> dchange(tr, pde, [x[1], x[2]]);

I am a begnnier of Maple. I have got some problems when solving the economic maximization problem.

When I set Digits:=15, then I could solve the problem and the solve command will give me the answer.

But when I set Digits:=20, it seems Maple cann't give me a numerical solution even I put restrictions on the form of solutions.

Can anybody help me about this?

Thank you!

I need a small help again. I have a basic question. Not able to figure how to do this.
(I am a newbie in Maple)

Maple handles things little different inside a proc() vs. global. http://www.maplesoft.com/support/help/Maple/view.aspx?path=procedure

And I could not understand what this below means in plain English:

Within a procedure, during the execution of its statementSequence, local
variables have
single level evaluation. This means that using a variable
in an expression will yield the current value of that variable, rather than
first evaluating that value. This is in contrast to how variables are evaluated
outside of a procedure, but is similar to how variables work in other programming languages.

 

But here is my question. In global name space, A variable inside an expression will automaticaly
update to the current value of the the variable. So one can do this:

x:='x';z:='z';
expr:=3*z;
z:=solve(x-1=0,x);
expr;

and now expr will have value "3" and not "3 z" since "z" was assigned a new numerical value in between
as one can see. The same code inside a proc()  behave differently

f:=proc()
  local z,x,expr;
  expr:=3*z;
  z:=solve(x-1=0,x);
  expr;
  end proc:

f();

return "3 z" and not "3" as the case with global scope. I tried subs() insid the proc,
but still it did not work. What is the recommded way to handle this? I want "expr" to
use the most recent value of any variables inside it. I can't do sub(z=z,expr) ofcourse
since this makes no sense. I need the value of z inside expr to be updated.i.e. I need
to refresh "expr" somehow.

 thank you,

Ok, I am not able to find about this after 30 minutes search (my limit of giving up :).

One can ofcourse make a local variables in a proc. But sometimes I need to make a temporary variable within the proc, say inside an if...fi to use for some local temporary computation. There is no need for this temporary variable to be declared at the whole proc() scope, since it is used only inside some limited scope.  I am not able to find how to do this in Maple. Here is some silly example

f:=proc()
     local x;
     x:=9;
     if x<10 then
        local z;
        z:=20;
        x:=z;
        ....
     fi;
     x;
     end proc;

the above is illegal. I can do this:

f:=proc()
     local x;
     x:=9;
     if x<10 then
        proc()
        z:=20;
        x:=z;
          ....
        end proc;    
     fi;
     x;
     end proc;
which compiles , but does not do what is expected. The body of the `if` statement is not called. I added a print statments there and they are not being called. (I guess since it is non-named proc(), it is not called, I thought it will fall through....

I looked for some kind of BLOCK , or DECLARE construct or such in Maple but can't find it.

is it possible to introduce a temporary local scope within a proc()? What would be the syntax? That would be really useful. Ada has this feature.

   

Hi,

My first post here.

I want to create my own questions on Maple T.A.  and it seems to me the User Guide is my only reference. Are there quick tutorials out there that I can refer to? Webinars would be helpful too.  I want to eventually create questions with partial credits.

Thanks in advance.

I could not find a way to do this in Maple looking at http://www.maplesoft.com/support/help/Maple/view.aspx?path=parameter_classes

and I see that Maple is missing from http://rosettacode.org/wiki/Named_parameters

Is it possible to call a Maple proc using named parameters? Here is an example of what this looks like from a small Ada example from the above link:

procedure Foo (Arg_1 : Integer; Arg_2 : Float := 0.0);
Foo (Arg_2 => 0.0, Arg_1 => 1);

This is very useful for proc with many arguments, and it also makes the code much
more clear and less change in using the wrong value for the wrong parameter.

In Maple notation, this can be like

foo:=proc(arg1::integer,arg2::float) ..... end proc;
foo(arg2=>10,arg1=>200);

(This editor is so bad, can't someone fix it?)
First 1156 1157 1158 1159 1160 1161 1162 Last Page 1158 of 2132