acer

32395 Reputation

29 Badges

19 years, 343 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

restart

with(plots); with(plottools)

interface(imaginaryunit = I)

L := `~`[[Re, Im]](sort([fsolve(x^8-1-I, x, complex)], key = argument))

display(pointplot(L, symbol = solidcircle, symbolsize = 20, color = red), polygon(L, style = line, thickness = 2, color = blue), gridlines)

NULL

Download ComplexQuestion_ac.mw

There are other ways to accomplish this kind of thing.

I'm not sure which you would consider as best, in part because I know little details about your actual examples or requirements. (Are they all numeric, are float results ok, is it supposed to be highly efficient or just easy, etc.)

with(LinearAlgebra):

A,b := <<0,1>|<0,0>>, <0,0>;

A, b := Matrix(2, 2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = 1, (2, 2) = 0}), Vector(2, {(1) = 0, (2) = 0})

S := LinearSolve(A, b);

Vector(2, {(1) = 0, (2) = _t10[2]})

evalindets(S,name,()->1);

Vector(2, {(1) = 0, (2) = 1})

evalindets(S,name,()->0);

Vector(2, {(1) = 0, (2) = 0})

LinearSolve(evalf(A), b, method=QR);

Vector(2, {(1) = 0., (2) = 0.})

LeastSquares(A, b, optimize);

Vector(2, {(1) = 0, (2) = 0})

LeastSquares(A, b, method=SVD);

Vector(2, {(1) = 0., (2) = 0.})

 

Download LSunder.mw

If your results have additional symbolic names in them (ie. that are present in the input, and are not just the introduced free parameters) then it is easy to adjust the evalindets 2nd argument (the type) to match only the introduced names. (With the base of the introduced parameter names under one's control there is no need to check also with a set intersection.)

with(LinearAlgebra):

A,b := <<0,u>|<0,v>>, <0,v>;

A, b := Matrix(2, 2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = u, (2, 2) = v}), Vector(2, {(1) = 0, (2) = v})

S := LinearSolve(A, b, free=_t);

Vector(2, {(1) = -v*(_t[2]-1)/u, (2) = _t[2]})

evalindets(S,indets(S,'specindex'(nonnegint,_t)),()->0);

Vector(2, {(1) = v/u, (2) = 0})

Download LSunder2.mw

You can access data structures directly using OpenMaple. You could go via a C extension to python.

Using the cmaple interface is not the really the right interface for the kind of interprocess memeory interaction you're describing.

I am not sure how you got in that bind, but here are a few adjustments (still using Equation Labels, etc), but with eval and unapply.

I used Maple 2018.2, to match your major version.

restart

with(Units)

Automatically loading the Units[Simple] subpackage

 

UseSystem('FPS')

UsingSystem()

FPS

(1)

Fin := 2*Unit('gal')/Unit('min')

(77/17280)*Units:-Unit(ft^3/s)

(2)

Cin := Unit('lb')/(2*Unit('gal'))

(288/77)*Units:-Unit(lb/ft^3)

(3)

Qin := Fin*Cin

(1/60)*Units:-Unit(lb/s)

(4)

Fout := 2*Unit('gal')/Unit('min')

(77/17280)*Units:-Unit(ft^3/s)

(5)

Cout := Q/(100*Unit('gal'))

(1/100)*Q*Units:-Unit(1/gal)

(6)

Qout := Fout*Cout

(1/3000)*Q*Units:-Unit(1/s)

(7)

``

Qin

(1/60)*Units:-Unit(lb/s)

(8)

theEq := diff(Q(t), t) = Qin-2*Q(t)*(1/100)

diff(Q(t), t) = (1/60)*Units:-Unit(lb/s)-(1/50)*Q(t)

(9)

dsolve(theEq)

Q(t) = (5/6)*Units:-Unit(lb/s)+exp(-(1/50)*t)*_C1

(10)

simplify(eval(Q(t) = (5/6)*Units[Unit](lb/s)+exp(-(1/50)*t)*_C1, _C1 = Unit(lb/min)))

Q(t) = (1/60)*(50+exp(-(1/50)*t))*Units:-Unit(lb/s)

(11)

q := unapply(rhs(Q(t) = (1/60)*(50+exp(-(1/50)*t))*Units[Unit](lb/s)), t)

proc (t) options operator, arrow; (1/60)*(50+exp(-(1/50)*t))*Units:-Unit(lb/s) end proc

(12)

q(10)

(1/60)*(50+exp(-1/5))*Units:-Unit(lb/s)

(13)

q(30)

(1/60)*(50+exp(-3/5))*Units:-Unit(lb/s)

(14)

``

evalf((1/60)*(50+exp(-3/5))*Units[Unit](lb/s))

.8424801942*Units:-Unit(lb/s)

(15)

``

Download units_issue_ac.mw

Do either of the attempts in this attachment work in your Maple 13?

Clutch_Modell_ac.mw

It's a little difficult for us, since the odeplot that seems problematic in your Maple 13 works in later versions (eg. Maple 16, Maple 2020).

I see that you've ignored my comment in your earlier duplicate of this topic, where you might consider another mechanism for the piecewise function than the unevaluated call to the unknown function(s).

Your procedure Basenwechsel itself uses the name Basenwechsel in two different ways.

Firstly, it assigns to the name Basenwechsel. as if to use it as a local variable. But secondly, it calls Basenwechsel in a function call (perhaps an attempt at a recursive call to itself).

Perhaps you can instead make Basenwechsel act recursively by using the procname syntax instead . See the attachment below.

Also, you have calls to with inside your procedures. That won't work properly. You could utilize the uses syntax within the procedures, or even more move them to the top level.

I suggest that you explicitly declare all the intended locals of your procedures, so that you know what they are doing. Don't rely on impliciat local declarations. And don't try and use the same name in two different ways.

Check whether this works as you hoped: Basenwechsel_ac1.mw

Did you mean that you wanted to shade the curve itself, or the area between y=0 and the curve, or something else?

If you just want to shade the curve with a single color then pass the color option, eg, color="Blue", etc.

  plot(x*ln(x), x=0..1, color="Blue");

If you want to shade the region between y=0 and y=x*ln(x) then pass the filled option.

If you want to shade the curve itself in a varying manner then you can pass an appropriate colorscheme option.

For example,

plot(x*ln(x), x=0..1, filled);

plot(x*ln(x), x=0..1,
     thickness=3,
     colorscheme=["ygradient", ["Blue", "Red"]]);

plot(x*ln(x), x=0..1,
     thickness=3,
     colorscheme=["xgradient", ["Blue", "Red"]]);

 

Download 2D_curve_shade.mw

There are other variations of coloring, etc.

overload seems to be the cause, and I think that it's a bug.

LinearAlgebra:-MatrixInverse is defined with overload, and has the problem. But LinearAlgebra:-LUDecomposition is not, and doesn't.

An example:

restart;

M:=module() option package;
  export f,g;
  f := overload([
         proc(x::positive) option overload; x^2; end proc,
         proc(x::negative) option overload; x; end proc ]);
  g := proc(x::positive) x^2; end proc;
end module:

with(M):

testf := proc()
           uses M;
           f(3);
         end proc:
testf();

f(3)

testg := proc()
           uses M;
           g(3);
         end proc:
testg();

9

okf := proc()
           f(3);
         end proc:
okf();

9

 

Download overload_fun.mw

There are several options that control the look and feel. But you might want to have the lower end-point of the x-range start a little above exact zero (to get some arrows near there). For example,

restart

alpha := .75; omega[1] := .15; omega[2] := .20; N := .8; beta[1] := .65; beta[2] := .70; Mu[1] := .75; Mu[2] := .74; h[1] := 0.5e-2; h[2] := 0.4e-2; d := 0.5e-1; E := .35

sys := [(D(x))(t) = alpha*x(t)*(1-x(t)/N)-beta[1]*sqrt(x(t))*y1(t)/(1+h[1]*beta[1]*sqrt(x(t)))-beta[2]*sqrt(x(t))*y2(t)/(1+h[2]*beta[2]*sqrt(x(t)))-d*E*x(t), (D(y1))(t) = -omega[1]*y1(t)+Mu[1]*beta[1]*sqrt(x(t))*y1(t)*(1-y1(t)/(beta[1]*sqrt(x(t))))/(1+h[1]*beta[1]*sqrt(x(t))), (D(y2))(t) = -omega[2]*y2(t)+Mu[2]*beta[2]*sqrt(x(t))*y2(t)*(1-y2(t)/(beta[2]*sqrt(x(t))))/(1+h[2]*beta[2]*sqrt(x(t)))]; RHS := eval(map(rhs, sys), [x(t) = x, y1(t) = y1, y2(t) = y2])

[.75*x*(1-1.250000000*x)-.65*x^(1/2)*y1/(1+0.325e-2*x^(1/2))-.70*x^(1/2)*y2/(1+0.280e-2*x^(1/2))-0.175e-1*x, -.15*y1+.4875*x^(1/2)*y1*(1-1.538461538*y1/x^(1/2))/(1+0.325e-2*x^(1/2)), -.20*y2+.5180*x^(1/2)*y2*(1-1.428571429*y2/x^(1/2))/(1+0.280e-2*x^(1/2))]

plots:-fieldplot3d(RHS, x = 0.1e-6 .. 1, y1 = 0 .. 1, y2 = 0 .. 1, grid = [7, 7, 7], axes = boxed, fieldstrength = average)

NULL

Download phaseportrait_ac.mw

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?

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.

First 121 122 123 124 125 126 127 Last Page 123 of 336