acer

18951 Reputation

29 Badges

14 years, 275 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

You wrote that you want them to "extend infinitely". What do you mean by that, precisely?

Do you mean that you want the y-axis's end-points to appear be +-infinity, and if so then how would you be able to recognize the scaling?

Or would it suffice if the visible y-range matched amongst all three curves?

restart;

f := x -> (ln(4*x-4)/4)-(ln(4*x+4)/4)+(arctan(x)/2):

plots:-display(
  plot([f(x), f(x)-2, f(x)+2], x=-10 .. -1-1e-8),
  plot([f(x), f(x)-2, f(x)+2], x=1+1e-8 .. 10),
  view=-5..5);

plot([f(x), f(x)-2, f(x)+2], x=1..10, y=-infinity..infinity);

 

Download yrange_inf.mw

The plot command will evaluate your call to your RMP procedure up front, before tau gets any numeric value. That is Maple's usual evaluation model.

But your procedure RMP is not set up to accept tau as just a name. The problem is that when your procedure RMP gets called promaturely -- with tau being just the non-numeric unassigned name -- the conditional comparisons t1 < tau and tau <= t2 cannot be done.

You can also see the difficulty if you simply execute the very same call to RMP outside of the plotting command.

Your situation is called "premature evaluation". It is a common issue for beginners in Maple.

Your Question's attachment was last saved in Maple 13. In modern Maple versions the magenta error message provides a URL to this description.

There are several ways to deal with it. Here are a few of them. (I have adjusted the chosen values for t1, A1, and t2 only so that it shows a more interesting actual plot.)

restart

RMP := proc (sl, t1, A1, t2, tau) local y; if t1 < tau and tau <= t2 then y := A1 end if; return y end proc:

RMP(2, 3, 3.7, 5, tau)

Error, (in RMP) cannot determine if this expression is true or false: 3 < tau and tau <= 5

('RMP')(2, 3, 3.7, 5, tau);

RMP(2, 3, 3.7, 5, tau)

plot(('RMP')(2, 3, 3.7, 5, tau), tau = 0 .. 6);

plot(proc (tau) options operator, arrow; RMP(2, 3, 3.7, 5, tau) end proc, 0 .. 6);

RMP2 := proc (sl, t1, A1, t2, tau) local y; if not type(tau, numeric) then return ('procname')(args) end if; if t1 < tau and tau <= t2 then y := A1 end if; return y end proc:

RMP2(2, 3, 3.7, 5, tau)

RMP2(2, 3, 3.7, 5, tau)

plot(RMP2(2, 3, 3.7, 5, tau), tau = 0 .. 6);

``

Download plotproc_acc.mw

By default the locals of a module are hidden from view, and cannot be arbitarily printed or called.

There are two ways to inspect them with showstat. One involves use a modification of the syntax for referring to module locals, another involves toggling off the hidden behaviour altogether.

restart;
showstat(((RandomTools::MersenneTwister)::MTKernelInterface));

MTKernelInterface := proc()
local n;
   1   n := kernelopts(('querybuiltin') = "RandNumberInterface");
   2   if n = -1 then
   3       error "kernel does not support %1", "RandNumberInterface"
       end if;
   4   unprotect(procname);
   5   assign(procname,eval(n));
   6   protect(procname);
   7   procname(_passed)
end proc

restart;
kernelopts(opaquemodules=false):
showstat(RandomTools:-MersenneTwister:-MTKernelInterface);

RandomTools:-MersenneTwister:-MTKernelInterface := proc()
local n;
   1   n := kernelopts(('querybuiltin') = "RandNumberInterface");
   2   if n = -1 then
   3       error "kernel does not support %1", "RandNumberInterface"
       end if;
   4   unprotect(procname);
   5   assign(procname,eval(n));
   6   protect(procname);
   7   procname(_passed)
end proc

You should show us what progress you've made so far with this coursework question.

If this is not homework then why not use relevant commands from the Student:-NumericalAnalysis package (eg. IterativeFormula or LinearSolve) in order to access an implementation of the Gauss-Seidel iterative method?

Or the LinearSolve command from the LinearAlgebra package, if you are just trying to obtain a reasonably robust or efficient solver?

If it is a homework question then you should be very clear about what stock commands from the Maple Library you are allowed to use. Can you use `.` to do Matrix multiplication? Can you use ForwardSubstitute or other package commands?

Do you mean that you want the visible axes to have the very same extent?

restart;
G:=(x,y)->2*x^2+y^2-2*(x+y+x*y-1):

plots:-implicitplot(G, -2..10, -2..10,
                    scaling=constrained,rangeasview);

plots:-implicitplot(G, -2..10, -2..10,
                    scaling=constrained,view=[0..6,0..6]);

You can use the DocumentTools:-Tabulate command to get such effects.

Tabulate_example.mw

I don't inline the attachment here, as this site's backend is old and doesn't support this feature so well.

It was only ever provided through here in the Maple Application Center (with the DLLs via a separate URL to a 3rd party site), if I recall correctly.

The cited 3rd party URL (or its parent site) seems to no longer be active or working.

I was able to download a 2009 snapshot of the cited .zip file by entering the URL cited on that Application Center page,
    http://www.ganso.com.au/libs/gansomapledlls.zip
in this internet archive site:
    https://archive.org/web/

So I suppose that you could test the Maple worksheet from that Application Center page, after putting the unzipped DLLs somewhere in the right path on a MS-Windows machine. There are some instructions in the worksheet. But the "wrapper" DLL (bridging functions between Maple and the computational DLL) seem to have been compiled for Maple 7, so it's not clear whether they will work in much later versions.

The entry on the Maple Application Centre listed the author as "Centre for Informatics and Applied Optimization (CIAO". But it's not clear whether that is related to this group.

There are lots of people who use a good Unix/Linux editor like Emacs or vi(m), yes.

I would mention Joe Riel's Emacs mode for Maple but I'm not sure if that is the correct link to the latest version. I had an idea that it was capable of interoperating with Maple's own debugger (the kernel/Library one, not the Maple GUI interface to it), but I'm not sure of the current status.

There are a few vim editor modes for Maple (highlighting, etc). You can find some just through a web search.

I lay out my Maple packages in text source files -- with a master .mpl file for the parent module definition, which uses the $include directives to read all the module members from their own individual source files.

Sometimes I write a fresh script or two to build/load/mint the .mpl Maple Library Archive and store the package into that, and sometimes I use some reusable scripts to do those steps (the scripts accept multiple arguments, to adjust the include-path, etc).

I use vim. For me, the key is having a few Linux terminal sessions. I use Maple's Command Line Interface (CLI) much more than I use the GUI. But I use both a great deal.

Your can also use zip to produced the list of 2-element lists. I have a slight preference for this because I find it slightly easier to recognize what the code is doing just by glancing at it a few months later.

You should choose whichever you find easier to understand, if high efficiency is not a major concern. Annotating your code with comments is also good.

You can also accomplish the pointplot by merging the two lists into an appropriate Matrix.

restart;

ListF:= [seq(x, x = -10..10, 1)]:

ListH:= [seq(x^2, x = -10..10, 1)]:

plots:-pointplot( <ListF|ListH>, size=[400,200]);

plots:-pointplot( zip(`[]`,ListF,ListH), size=[400,200]);

zip(`[]`,ListF,ListH);

[[-10, 100], [-9, 81], [-8, 64], [-7, 49], [-6, 36], [-5, 25], [-4, 16], [-3, 9], [-2, 4], [-1, 1], [0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81], [10, 100]]

`[]`~(ListF,ListH);

[[-10, 100], [-9, 81], [-8, 64], [-7, 49], [-6, 36], [-5, 25], [-4, 16], [-3, 9], [-2, 4], [-1, 1], [0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81], [10, 100]]

[seq([ListF[i],ListH[i]], i=1..nops(ListF))];

[[-10, 100], [-9, 81], [-8, 64], [-7, 49], [-6, 36], [-5, 25], [-4, 16], [-3, 9], [-2, 4], [-1, 1], [0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81], [10, 100]]

 

restart;

ListF:= [seq(x, x = -10..10, 1.0)]:

ListH:= [seq(sin(x), x = -10..10, 1.0)]:

FH := zip(`[]`,ListF,ListH);

[[-10, -sin(10)], [-9.0, -.4121184852], [-8.0, -.9893582466], [-7.0, -.6569865987], [-6.0, .2794154982], [-5.0, .9589242747], [-4.0, .7568024953], [-3.0, -.1411200081], [-2.0, -.9092974268], [-1.0, -.8414709848], [0., 0.], [1.0, .8414709848], [2.0, .9092974268], [3.0, .1411200081], [4.0, -.7568024953], [5.0, -.9589242747], [6.0, -.2794154982], [7.0, .6569865987], [8.0, .9893582466], [9.0, .4121184852], [10.0, -.5440211109]]

with(CurveFitting):
polyInterFH:= PolynomialInterpolation(FH,x):

plot(polyInterFH, x=min(ListF) .. max(ListF), size=[400,200]);

plots:-display(
  plots:-pointplot( zip(`[]`,ListF,ListH), size=[400,200]),
  plot(PolynomialInterpolation(ListF, ListH,x),
       x=min(ListF) .. max(ListF), size=[400,200])
);

 

Download list_zip.mw

This is an attempt at part ii) using your earlier methodology of Arrays and loops. You may be able to bend it to your task. You certainly don't have to do it this way. (It's not my preference.)

There are easier ways to get all the intersections with the unit circle, but it asked for fsolve specifically in part i). [edited] I've much added easiers ways, using solve or RootFinding:-Isolate.

By now, you should realize that usually there are several reasonable ways to do most things in Maple, and often no "best" way. Tweak, adjust, and rewite as you wish.

I deliberately do some of this in a way that I consider awkward (and somewhat inefficient). It is on purpose. I realize that you are still learning Maple. I'd rather show you a somewhat clunky approach that you can figure out and understand than a slick solution that is opaque to you.

restart;

#H := (x,y)->x^3-x*y-1;
#H := (x,y) -> x^3 - 2*y^2 + 3/2;
H := (x,y) -> x^2*y + x^3 + x*y^3 + y + 1;

proc (x, y) options operator, arrow; x^2*y+x^3+x*y^3+y+1 end proc

 

part ii)

 

ImpDH := implicitdiff(H(x,y), y, x);

-(y^3+3*x^2+2*x*y)/(3*x*y^2+x^2+1)

hlist := [-0.5, 0.0, 0.5]:
P := Array(1..nops(hlist), 1..7):

for i from 1 to nops(hlist) do
  P[i, 1] := hlist[i];
  P[i, 2] := H(1+hlist[i],y)=0;
  P[i, 3] := [fsolve(P[i, 2], y, maxsols=10)];
  P[i, 4] := [seq( [1+P[i, 1], P[i, 3][1]],
                   j=1..nops(P[i, 3]))];
  P[i, 5] := [seq( eval(ImpDH, [x=P[i, 4][j][1], y=P[i, 4][j][2]]),
                   j=1..nops(P[i, 3]))];
  P[i, 6] := [seq( P[i, 4][j][2] + P[i, 5][j]*(x-P[i, 4][j][1]),
                   j=1..nops(P[i, 3]))];
  P[i, 7] := [seq( plot(P[i, 6][j], x=0..2,
                        color=sprintf("Bright %a",i+2),
                        legend=typeset("tangent at",
                                       evalf[3](P[i, 4][j]))),
                   j=1..nops(P[i, 3]))];;
end do:

plots:-display(
  plots:-implicitplot(H, 0..2, -2..5,
                      legend=typeset(H(x,y)),
                      thickness=2, color=red),
  seq(seq( P[i, 7][j], j=1..nops(P[i, 3])), i=1..nops(hlist)),
  seq(plots:-pointplot(P[i, 4], symbol=solidcircle,
                       symbolsize=15, color=blue),
      i=1..nops(hlist)),
  size=[700, 400],
  legendstyle=[location=right]
);

 

For part i)

 

PH := plots:-implicitplot(H, -4..2, -4..5, rangeasview):

# This could be done more easily, but fsolve was requested.
T := table([]):
no_more := false: count:=0:
while no_more = false and count < 10 do
  temp := fsolve([H(x,y)=0, x^2+y^2=1], {x=-4..2, y=-4..5}
                 , avoid = {entries(T, nolist)}
                  );
  if type( eval(temp,1), set) then
    count := count+1;
    # sometimes fsolve with `avoid` has trouble finding all
    # the roots, so give it a little prod.
    # Alternatively we could pass the other three as initial
    # points in their own calls to fsolve.
    T[count] := {op(Equate([x,y],eval([x,y], temp)))},
                {op(Equate([x,y],eval([-x,y], temp)))},
                {op(Equate([x,y],eval([x,-y], temp)))},
                {op(Equate([x,y],eval([-x,-y], temp)))};
    # This check is pretty crude.
    T[count] := seq(`if`(abs(H(op(eval([x,y],r))))<=1e-9,r,NULL),
                    r = [T[count]]);
  else
    no_more := true;
  end if;
end do:
sols := map(r->eval([x,y],r), [op(simplify(fnormal({ entries(T, nolist)})))]);

[[-1.000000000, 0.], [-.6023240113, -.7982517055], [0., -1.000000000], [.6906238640, -.7232141305]]

#
# Surely it is easier to just use solve for these
# bivariate polynomials.
#
sols := map(r->eval([x,y],r),
            evalf([solve({H(x,y)=0, x^2+y^2=1, x>=-4, x<=2, y>=-4, y<=5})]));

[[0., -1.], [-.602324011, -.7982517055], [.690623864, -.7232141305], [-1., 0.]]

RootFinding:-Isolate([H(x,y), x^2+y^2-1], [x,y]);

[[x = 0., y = -1.], [x = -.6023240113, y = -.7982517055], [x = .6906238640, y = -.7232141305], [x = -1., y = 0.]]

plots:-display(PH, plottools:-circle([0,0], 1),
               plots:-pointplot(sols, color=blue, symbol=solidcircle));

 

Download ex_set_2_task_7_acc.mw

If you know that what is inside the csgn is positive, then you can evaluate under that assumption.

For example,  12_ac.mws

The expression sqrt(2*x+7) doesn't mean both the positive and negative square root.

solve( Or(sqrt(2*x+7)-x-2, -sqrt(2*x+7)-x-2), [x] );

[[x = -3], [x = 1]]

H := RootOf(_Z^2 - (2*x+7));

RootOf(_Z^2-2*x-7)

allvalues(H);

(2*x+7)^(1/2), -(2*x+7)^(1/2)

solve( H - x - 2, [x] );

[[x = 1], [x = -3]]

 

Download sqrt_RootOf.mw

I don't get an error if I used eval instead of subs to do the substitution.

simplification_error_ac.mw

I didn't bother to check which term gave a problematic (diff?) term.

Why did you choose subs to do a mathematical substitution?

The following will work not work in Maple 17 (released 2013), since DataFrames and Tabulate don't exist in that version. But it would work if you actually have Maple 2017, which is a different, later release.

You could augment the Matrix with an extra column and row, and then use the DocumentTools:-Tabulate command on that to display it nicely.

Or you could put the Matrix into a DataFrame, and call Tabulate directly on that. Here is an example of that. (It looks nicer in Maple's own GUI, and appears centered by default though that is optional.) 

restart;

S:=Matrix([[0,9,8,0,7],[3,5,6,5,1],
           [1,0,0,3,2]]);

Matrix(3, 5, {(1, 1) = 0, (1, 2) = 9, (1, 3) = 8, (1, 4) = 0, (1, 5) = 7, (2, 1) = 3, (2, 2) = 5, (2, 3) = 6, (2, 4) = 5, (2, 5) = 1, (3, 1) = 1, (3, 2) = 0, (3, 3) = 0, (3, 4) = 3, (3, 5) = 2})

DF:=DataFrame(S,
              rows=["small","medium","large"],
              columns=["Rose","Teal","Plum","Sand","Peach"]):

Tabulate(DF, widthmode=pixels, width=400):

 

 

Rose

Teal

Plum

Sand

Peach

small

0

9

8

0

7

medium

3

5

6

5

1

large

1

0

0

3

2

 

 

DF_example.mw

You already have the exact value. (The cube root of 2 is irrational, and a positive integer multiple of it is also irrational and cannot be expressed exactly as a rational -- if that's what you were expecting. That's mathematics, not just Maple.)

You can get a floating-point approximation using the evalf command.

C__temp1:=2^((105-25)/6);                                                         

                                 (1/3)
               C__temp1 := 8192 2

evalf(C__temp1);                                                                  

                    10321.27324

evalf[20](C__temp1);                                                              

                10321.273240738800966
3 4 5 6 7 8 9 Last Page 5 of 218