awass

296 Reputation

10 Badges

19 years, 41 days

MaplePrimes Activity


These are replies submitted by awass

@Preben Alsholm THank you for your clear explanation of piecewise.

 

As to Maple "knowing" about laplace I meant that when dsolve is called with  my linear ODE system with constant coefficients and initial conditions it takes what seems like forever to find a solution without my hint (method = laplace). I would think method = laplace might be the default.

@Carl Love 

OK Here is the code. Thx
restart;
Typesetting[Settings](useprime,prime = t);
                            true, x


R := piecewise(t < 0.1e-7, 57, t > 0.1e-7, 57-48*exp(-t+0.1e-7)/(0.1e-7));


print(`output redirected...`); # input placeholder
 R :=  /                                                    -8
       |                  57                        t < 1 10  
      <                                                       
       |                    9    /         -8\          -8    
       \ 57 - 4.800000000 10  exp\-t + 1 10  /      1 10   < t


dsolve({diff(y(t), t)-R(t)*y(t)^2 = 0, y(0) = 1}, numeric);
%;
Error, (in unknown) invalid input: `dsolve/numeric/lexorder` expects its 2nd argument, b, to be of type {indexed, name, numeric}, but received piecewise(t < 0.1e-7, 57, 0.1e-7 < t, 57-4800000000.*exp(-t+0.1e-7))


dsolve({diff(y(t), t)-R(t)*y(t)^2 = 0, y(0) = 1}, numeric);
%;
Error, (in unknown) invalid input: `dsolve/numeric/lexorder` expects its 2nd argument, b, to be of type {indexed, name, numeric}, but received piecewise(t < 0.1e-7, 57, 0.1e-7 < t, 57-4800000000.*exp(-t+0.1e-7))


dsolve({diff(y(t), t)-7*y(t) = R(t), y(0) = 1}, numeric);
%;
Error, (in unknown) invalid input: `dsolve/numeric/lexorder` expects its 2nd argument, b, to be of type {indexed, name, numeric}, but received piecewise(t < 0.1e-7, 57, 0.1e-7 < t, 57-4800000000.*exp(-t+0.1e-7))




@tomleslie 

Thanks for the explanation.

 

TRy these examples: (you might be surprised by the first 2.

cat(x,i);
                               
cat(x,"i");
                              
cat("x",i);
                              "xi"
StringTools:-Join([x,i]);
                             "x i"

@acer 

Thanks for straightening me out on that.

@Carl Love 

Hi,

I have looked at your answer and the try-catch help pages but now I am confused about usage.

I want to do a computation, if possible, but if not-if an error of any type is returned I want to do an alternative computation. For example, I define a (silly) function f that can fail to return  a value for either of 2 reasons and returns different error messages for the 2 values,


restart;
f:=proc(x)
if x=8 then error "bad value" else 1/(7-x) end if
end proc;
                    f := proc(x)  ...  end;
f(3);
                               1
                               -
                               4
f(8);
Error, (in f) bad value


f(7);
Error, (in f) numeric exception: division by zero


Now I use try-catch to introduce an alternative.


try
c:=f(8)
catch :
c:=17
end try;
                            c := 17

Fine!


try
c:=f(7)
catch :
c:=17
end try;
                            c := 17

Fine again!


At this point I think I understand the basic usuage but ...


try
c:=1/(7-7)
catch:
c:=17
end try;
Error, numeric exception: division by zero
c;
                               c


Try-catch does not work in this simple situation. Howver, inside a do loop it does work!


restart;
for j from 1 to 10 do
try
b[j]:=1/(7-j)
catch :
b[j]:=17
end try
end do;
b[6];
                               1
b[7];
                               17
b[9];
                               -1
                               --
                               2


Here is another situation in which it works as expected:


restart;
try
c:=1/ln(1)
catch:
c:=17
end try;
                            c := 17
Is there some simple preprocessor that prevents try-catch from working as expected?

Thank you for your answers. I will now try (no pun intended) to use that.

 

I have just looked at the Maple Help page for try-catch and I do wish here were more examples-I find it much easier to learn from examples than "explanations". Makes me think about all the years I tortured my students with "explanatins".

@Carl Love 

 

Thank you.

Good to know.

@Markiyan Hirnyk 

 

I noticed this also-more than 3 notifications and they happened after I had responded.

 

On the other hand many comments and replies  disappeared from my questions as saved.

@Alejandro Jakubi 

That makes sense. Is there a simple way to do the "heavy" work in the CLI and then transfer the results to the GUI version for display?

I was not familiar with the command line interface but I tried it and command period did stop the computation. (BTW, that is one fast interface!)

@Carl Love  Thank you for your reply.

 I did not think of using eval that way; it is easier yet.

@Carl Love  Thank you for your reply.

 I did not think of using eval that way; it is easier yet.

@Carl Love 

Thanks for the pointer to the documentation and the explanation. I am glad it all makes sense; I will let the subtleties pass me by.

By the way, is it considerd good practice to use the "use" command as follows?

>use d=3,a=5 in plot(x^d,x=0.1..a) end use;

I can see many situations where it is preferable to "subs" or "assuming"

@Carl Love 

Thanks for the pointer to the documentation and the explanation. I am glad it all makes sense; I will let the subtleties pass me by.

By the way, is it considerd good practice to use the "use" command as follows?

>use d=3,a=5 in plot(x^d,x=0.1..a) end use;

I can see many situations where it is preferable to "subs" or "assuming"

4 5 6 7 8 9 Page 6 of 9