acer

32333 Reputation

29 Badges

19 years, 322 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

plot3d(piecewise(x^2+y^2<=1,0,undefined), y=-1..1, x=-1..1,
       lightmodel=none,
       image=cat(kernelopts(homedir),"/mapleprimes/","penny.png"));

For this example we can discern the greatest argument in a call to F, and isolate for that up front.

restart;

term := (r+1)*(r+2)*(r+3)*(r+4)*F(r+4)*(k-r+1)*F(k-r+1):

H := isolate(sum(term, r=0..k-1)
             +eval(term, r=k)=c, F(k+4));

F(k+4) = (c-(sum((r+1)*(r+2)*(r+3)*(r+4)*F(r+4)*(k-r+1)*F(k-r+1), r = 0 .. k-1)))/((k+1)*(k+2)*(k+3)*(k+4)*F(1))

Q := unapply(H, k):

Q(0);

F(4) = (1/24)*c/F(1)

Q(1);

F(5) = (1/120)*(c-48*F(4)*F(2))/F(1)

Q(2);

F(6) = (1/360)*(c-72*F(4)*F(3)-240*F(5)*F(2))/F(1)

 

Download gen.mw

Try it like this instead, in your Maple 2018,

restart;

with(DEtools):

rho := 0.1:
w0 := 2:
sys := a->[diff(x(t),t) = y(t),diff(y(t),t) = -2*rho*y(t) - w0^2*(x(t)+a)]:
P:=a->DEplot(sys(a), [x(t),y(t)], t = 0 .. 20-2*a, x=-2..2, y=-1.9..1.7,
             [[x(0) = cos(a)-a, y(0) = sin(a)]], scene = [x(t),y(t)],
             linecolor=blue, numpoints=1000):

plots:-animate(P, [a], a=-0.7..1.4, frames=25, size=[600,300]);

 

Download animate_size.mw

That sizing is respected by the right-click context-menu export to .gif on my Maple 2018.2.

Alternatively, if you have already created the animation, you can resize it like so,

PA:=plots:-animate(P, [a], a=-0.7..1.4, frames=25):
plots:-display(PA, size=[600,300], insequence=true);

Did you forget to first load the CurveFitting package? Try executing this command first,

   with(CurveFitting):

Alternatively, you can call it by its so-called long-form name CurveFitting:-PolynomialInterpolation.

restart;

xdat:=[[0,3],[1,0],[2,4],[3,4],[4,-1],[6,4],[7,0],[9,2],[10,10]];

[[0, 3], [1, 0], [2, 4], [3, 4], [4, -1], [6, 4], [7, 0], [9, 2], [10, 10]]

with(CurveFitting):

PolynomialInterpolation(xdat,x);

-(197/181440)*x^8+(361/9072)*x^7-(52681/90720)*x^6+(24331/5670)*x^5-(3053693/181440)*x^4+(301219/9072)*x^3-(136243/5040)*x^2+(4927/1260)*x+3

restart;

xdat:=[[0,3],[1,0],[2,4],[3,4],[4,-1],[6,4],[7,0],[9,2],[10,10]];

[[0, 3], [1, 0], [2, 4], [3, 4], [4, -1], [6, 4], [7, 0], [9, 2], [10, 10]]

CurveFitting:-PolynomialInterpolation(xdat,x);

-(197/181440)*x^8+(361/9072)*x^7-(52681/90720)*x^6+(24331/5670)*x^5-(3053693/181440)*x^4+(301219/9072)*x^3-(136243/5040)*x^2+(4927/1260)*x+3

 

Download PolyInterp.mw

You claim that a call to EigValsVecsC executes properly when called from withing Visual Studio. So then the function LAPACKE_dsyev is being found at run time. Whence is it be found, by Visual Studio?

That missing function's name is from a suite for calling Fortran LAPACK from C. How is Visual Studio linking to a .dll that contains that function? Presumably operators.dll is being built in Visual Studio by being linked against some LAPACKe .dll(s). But only you can tell us how you set up that project.

When you try to call EigValsVecsC using Maple's define_external then it's not going to know where to find the .dll that contains that auxillary LAPACKe function LAPACKE_dsyev. Why/How should it know, if you haven't put it in a directory that is in the runtime path?

You could try adding the relevant LAPACKe .dlls (that contain LAPACKE_dsyev and any supporting functions) to the runtime path. You may need to try a few variations on that, since Maple's directory for executables and .dlls contains it own MKL LAPACK .dlls (but not LAPACKe, if I recall).

[edit] Perhaps you could provide a detailed description of what you're trying to achieve?

 

 

I'm not sure how exacty you want it to look. But here's a start.

insert_pictures_ac.mw

Below I first inline and attach a worksheet that does this in a very simple way.

Then at the end I attach another worksheet whose Startup Code contains a rough version of a package that provides some more automatic support for such things (eg. some Units support, convert/combine/evalc/Re/Im/etc, and a few context-menu items). Sorry, it's got an accidental quirk in its static evalf export that makes it a bit awkward to work with float values -- I ought to fix that.

Sorry that the 2D Math parser is so picky about brackets around floats and negative values for the infix `&angle;` operator. You can find that on the "Operators" palette, by the way (and you can add it to your Favorites palette). There's a bit of GUI weirdness around.

This first approach below doesn't need any add-on. [edit] Carl Love did something similar once, if I recall, but I cannot find that post at the moment.

restart

I want to calculate the voltage between phase 1 and phase N in an electrical circuit:``

 

The vectorial formula is:

`#mover(mi("U"),mo("&rarr;"))`[L1-N]-`#mover(mi("&Delta;U",mathcolor = "blue"),mo("&rarr;",mathcolor = "blue"))`[L1]+`#mover(mi("&Delta;U",mathcolor = "#339966"),mo("&rarr;",mathcolor = "#339966"))`[N] = `#mover(mi("U",mathcolor = "red"),mo("&rarr;",mathcolor = "red"))`[L1-N]

`#mover(mi("U"),mo("&rarr;"))`[L1-N]-`#mover(mi("&Delta;U",mathcolor = "blue"),mo("&rarr;",mathcolor = "blue"))`[L1]+`#mover(mi("&Delta;U",mathcolor = "#339966"),mo("&rarr;",mathcolor = "#339966"))`[N] = `#mover(mi("U",mathcolor = "red"),mo("&rarr;",mathcolor = "red"))`[L1-N]

 

Voltage drops are calculated with the current multiplied with the resistance: ΔU = I*Z[L]

I*Z[L]

 

i

 

-`#mover(mi("I",mathcolor = "blue"),mo("&rarr;",mathcolor = "blue"))`[L1]*`#mover(mi("Z",mathcolor = "#ff99cc"),mo("&rarr;",mathcolor = "#ff99cc"))`[L]+`#mover(mi("I",mathcolor = "#339966"),mo("&rarr;",mathcolor = "#339966"))`[N]*`#mover(mi("Z",mathcolor = "#ff99cc"),mo("&rarr;",mathcolor = "#ff99cc"))`[L]+`#mover(mi("U"),mo("&rarr;"))`[L1-N] = `#mover(mi("U",mathcolor = "red"),mo("&rarr;",mathcolor = "red"))`[L1-N]``

-`#mover(mi("I",mathcolor = "blue"),mo("&rarr;",mathcolor = "blue"))`[L1]*`#mover(mi("Z",mathcolor = "#ff99cc"),mo("&rarr;",mathcolor = "#ff99cc"))`[L]+`#mover(mi("I",mathcolor = "#339966"),mo("&rarr;",mathcolor = "#339966"))`[N]*`#mover(mi("Z",mathcolor = "#ff99cc"),mo("&rarr;",mathcolor = "#ff99cc"))`[L]+`#mover(mi("U"),mo("&rarr;"))`[L1-N] = `#mover(mi("U",mathcolor = "red"),mo("&rarr;",mathcolor = "red"))`[L1-N]

This is a real example with realistic values and angles:

`&angle;` := proc (a, b) polar(a, (1/180)*b*Pi) end proc; ex := proc (v) abs(v), 180*argument(v)/Pi end proc

`#mover(mi("U"),mo("&rarr;"))`[L1-N] := `&angle;`(230.0, 0)

polar(230.0, 0)

`#mover(mi("I",mathcolor = "blue"),mo("&rarr;",mathcolor = "blue"))`[L1] := `&angle;`(20.0, -30)

polar(20.0, -(1/6)*Pi)

`#mover(mi("Z",mathcolor = "#ff99cc"),mo("&rarr;",mathcolor = "#ff99cc"))`[L] := `&angle;`(0.97e-1, 7.2)

polar(0.97e-1, .1256637062)

`#mover(mi("I",mathcolor = "#339966"),mo("&rarr;",mathcolor = "#339966"))`[N] := `&angle;`(40.0, -120)

polar(40.0, -(2/3)*Pi)

 

The negative angles is because i am using my reference which is in 0°. And are the vector to the right of my reference is the angle negative, and is it on the left of my reference is the angle negative. I dont want to explain the vectorial diagram, because i think it will do more confusion than explaining.

 

NULL

ex(simplify(`&angle;`(230, 0)-`&angle;`(20, -30)*`&angle;`(0.97e-1, 7.2)+`&angle;`(40, -120)*`&angle;`(0.97e-1, 7.2))) = `#mover(mi("U",mathcolor = "red"),mo("&rarr;",mathcolor = "red"))`[L1-N]

(226.7256260, -.7139358882) = `#mover(mi("U",mathcolor = "red"),mo("&rarr;",mathcolor = "red"))`[L1-N]

My question is, if the formula above is possible to solve in maple?

ex(simplify(-`#mover(mi("I",mathcolor = "blue"),mo("&rarr;",mathcolor = "blue"))`[L1]*`#mover(mi("Z",mathcolor = "#ff99cc"),mo("&rarr;",mathcolor = "#ff99cc"))`[L]+`#mover(mi("I",mathcolor = "#339966"),mo("&rarr;",mathcolor = "#339966"))`[N]*`#mover(mi("Z",mathcolor = "#ff99cc"),mo("&rarr;",mathcolor = "#ff99cc"))`[L]+`#mover(mi("U"),mo("&rarr;"))`[L1-N])) = `#mover(mi("U",mathcolor = "red"),mo("&rarr;",mathcolor = "red"))`[L1-N]

(226.7256260, -.7139358882) = `#mover(mi("U",mathcolor = "red"),mo("&rarr;",mathcolor = "red"))`[L1-N]

``

Download Example_to_Mapleprimes_ac2.mw

And here's the other worksheet I mentioned, using a rough prototype of my "Phasors" package in the Startup Code region. [edit] To utilize this in another worksheet you'd have to copy the Startup Code, since I have not yet made it into a downloadable package from the Maple cloud.

Example_to_Mapleprimes_ac.mw

note: "Phasor" may not be the best term here. "degree-polar" might be better. Are the multiplications in your calculation meant to represent something like a phasor multiplied by a complex value? Or phasor-phasor product?
note: What was the precise result from your calculator?

Your expectation indicates that you have not read and understood the relevant part of the interface help page.

Regarding the errorbreak setting, the help page for topic interface says, "Controls Maple's behavior when an error occurs while reading Maple commands from a file or redirected standard input, as follows:..."

That description does not state that it controls the general flow of an executing worksheet.

Inside the GUI, the setting of interface(errorbreak) affects the behavior during execution of the read command. It controls the error severity level that will stop further reading of the plaintext file's Maple statements.

Let us know if you really need the appearance of the addends to be of the form wf δ θf (...)  etc.  That could be done as a visual effect, since normally some of those terms would automatically simplify (eg. wf*delta*wf automatically simplifies to delta*wf^2). The other terms could be managed using special invocation of the `sort` command. But the squares are trickier.

The addends in ans1 below are mathematically as you asked, if I understand correctly. The precise formatting is also possible -- but it'd be just that, a pretty-printing affect.

restart

c := -(lambda*`&theta;f`+lambda*`&theta;i`+2*wf-2*wi)/lambda^3

d := (lambda*`&theta;f`+2*lambda*`&theta;i`+3*wf-3*wi)/lambda^2:

g := 6*c*x+2*d:

h := delta*g:

expr := expand(g*h)

4*delta*`&theta;f`^2/lambda^2+16*delta*`&theta;i`^2/lambda^2+36*delta*wi^2/lambda^4+36*delta*wf^2/lambda^4+72*delta*x^2*`&theta;f`*`&theta;i`/lambda^4+144*delta*x^2*`&theta;f`*wf/lambda^5-144*delta*x^2*`&theta;f`*wi/lambda^5-72*delta*x*`&theta;f`*`&theta;i`/lambda^3-120*delta*x*`&theta;f`*wf/lambda^4+120*delta*x*`&theta;f`*wi/lambda^4+144*delta*x^2*`&theta;i`*wf/lambda^5-144*delta*x^2*`&theta;i`*wi/lambda^5-168*delta*x*`&theta;i`*wf/lambda^4+168*delta*x*`&theta;i`*wi/lambda^4-288*delta*x^2*wf*wi/lambda^6+288*delta*x*wf*wi/lambda^5+36*delta*x^2*`&theta;f`^2/lambda^4+144*delta*x^2*wi^2/lambda^6+24*delta*`&theta;f`*wf/lambda^3-72*delta*wf*wi/lambda^4-144*delta*x*wi^2/lambda^5+16*delta*`&theta;f`*`&theta;i`/lambda^2-24*delta*x*`&theta;f`^2/lambda^3-48*delta*x*`&theta;i`^2/lambda^3+144*delta*x^2*wf^2/lambda^6+48*delta*`&theta;i`*wf/lambda^3-48*delta*`&theta;i`*wi/lambda^3+36*delta*x^2*`&theta;i`^2/lambda^4-144*delta*x*wf^2/lambda^5-24*delta*`&theta;f`*wi/lambda^3

L := [wi, wf, `&theta;f`, `&theta;i`];

[wi, wf, `&theta;f`, `&theta;i`]

CC := map(proc (p) options operator, arrow; delta*(`*`(op(p))) end proc, C):

ee := expand(expr):

ans1 := thaw(collect(ee, map(rhs, CCC), simplify));

36*delta*wi^2*(lambda^2-4*lambda*x+4*x^2)/lambda^6-72*(lambda^2-4*lambda*x+4*x^2)*delta*wf*wi/lambda^6-24*(lambda^2-5*lambda*x+6*x^2)*delta*`&theta;f`*wi/lambda^5-24*`&theta;i`*(2*lambda^2-7*lambda*x+6*x^2)*wi*delta/lambda^5+36*(lambda^2-4*lambda*x+4*x^2)*wf^2*delta/lambda^6+24*(lambda^2-5*lambda*x+6*x^2)*delta*`&theta;f`*wf/lambda^5+24*`&theta;i`*(2*lambda^2-7*lambda*x+6*x^2)*wf*delta/lambda^5+4*(lambda^2-6*lambda*x+9*x^2)*`&theta;f`^2*delta/lambda^4+8*`&theta;i`*(2*lambda^2-9*lambda*x+9*x^2)*`&theta;f`*delta/lambda^4+4*(4*lambda^2-12*lambda*x+9*x^2)*`&theta;i`^2*delta/lambda^4

simplify(expr-ans1);

0

``

Download Final_objective_orig_ac.mw

 

This has been asked several times in the past. There are at least half a dozen different ways to approach implementing it.

See responses to these old Questions:  here, here, and here, (or this zany answer).

There are also variations on some of those (ie. the first cited link's Answers) where the InertForms package or manually constructed Typeset 2D Math can display the chain of intermediary and final results in a single output line. This can help get rid of some extraneous brackets in the final display. Personally, I find InertForms to be somewhat clunky -- but I don't recall revisiting the whole question and generating a variant that constructs the Typeset 2D Math behind the scenes.

It could help if you gave us the hardest example that you expect to handle, and describe exactly how you want it to appear. There are too many ways to code it up so that your toy example looks fine but more involved examples (eg. more intermediate steps, things other than simple arithmetic, etc) don't look best. 

Do you need the operators (+, *, etc) to display as usual, or would a lighter gray shade be ok?

In the case of a deeper level of assignment do you want to see each level displayed or just the final numeric values before evaluation? For example, x:=y; y:=z; z:=4.0; and then would input sin(x) show just the additional unevaluated sin(4.0) = -0.757...?

Also important is whether you expect the return-value to be as usual (just the last item in your chain). Is it ok to have the usual return-value, whose usual echoing is suppressed by you (ending your statement with a colon), and your desired chain be merely printed as side-effect? Or can/should the return-value be something that echoes like your displayed chain?

I understand that some of these subtleties may seem hard to grasp, as a beginner. That's why I showed the variety of those cited responses.

Here's an example, necessarily simple because you haven't yet provided a clear description of the data and goal.

restart;

N:=20:

P1:=[seq(plot([[N-i,N-i]],style=point,symbolsize=30,symbol=solidcircle,
              color=gold,transparency=1-evalf(i/N)),i=1..N)]:

P2:=plot([seq([N-i,N-i],i=1..N)],style=point,symbolsize=30,symbol=solidcircle,
         colorscheme=["xgradient",[gold,white]]):

 

If you don't intend on overlaying the points on any other plot artefact (ie. just a white background), then it's simpler to adjust the coloring than to deal with separate transparency for each point.

 

In that case, if you want the fade to be either vertically or horizontally applied, then it's easier still to simply use the colorscheme option.

 

Computing the transparency value from a precomputed set of points is also possible, but brings the extra burden of mapping the range of the point values into the range 0..1. If that's your situation, and if you really do need that variant, then let us know.

 

plots:-display(P1[]);
P2;

 

A visual distinction appears, of course, if you overlay the points on some other plot artefact (a shaded polygon, or a background).

 

But so far it's unclear whether you need this.

 

P1all:=plots:-display(P1[],
                      plottools:-polygon([[0,0],[10,0],[10,10],[0,10]],color=blue),
                      plottools:-polygon([[10,10],[20,10],[20,20],[10,20]],color=red));

P2all:=plots:-display(P2,
                      plottools:-polygon([[0,0],[10,0],[10,10],[0,10]],color=blue),
                      plottools:-polygon([[10,10],[20,10],[20,20],[10,20]],color=red));

 

Download point_transparency.mw

You are using the wrong command.

StringTools:-Has is for testing for the presence of a single character. Read its help page. That pages states, "Furthermore, if the length of ch is greater than 1, then characters in ch after the first are ignored." So your calls to StringTools:-Has are merely testing for the presence of "_".

You could instead try testing whether StringTools:-Search succeeds, ie. returns a nonzero result.

@Christian Wolinski That's an error message coming out of Maple's Java GUI, rather than the Maple kernel. It means that you've tried to display/print an invalid plotting structure.

What makes you think that RGBA is a valid colorspace specification for the COLOR substructure of a plotting structure? It is not. The valid values are RGB, HSV, and HUE. That is documented on the Maple help page with topic plot,structure

Why don't you answer the question about how the problematic plotting structure was created? Did you construct it directly, rather than obtaining it from some Library plotting command?

I suspect that you are trying to utilize a fourth alpha color channel within a constructed plot structure (related to this recent Question), but that is not supported by the COLOR/COLOUR plotting substructure.

The message is displayed when the GUI tries to print the invalid structure. Depending on what else is in the whole structure some partial plot may be rendered. For example,

restart;

p1:=PLOT(POINTS([2,3],COLOR(RGB, 0, 0, 1))):

p2:=PLOT(POINTS([2,3],COLOR(RGBA, 0, 0, 1))):

p1;

p2;

com.maplesoft.mathdoc.model.plot.PlotException: Unrecognized option in COLOR: RGBA

 

Download RGBA_error.mw

The commandline interface emits a slightly different message, eg, Error, invalid COLOUR argument RGBA

 

The computations are not the same, and are done with different floating-point models by default.

By default the scalar-Vector multiplication is done using hardware double precision (since the scalar and Vector entries are of type numeric and the datatype of the Vector is 'anything'). The result is a datatype=float[8] Vector.

The same effect can be obtained for your second example, involving scalar-scalar multiplication, by casting both arguments to HFloat.

You can turn that off by setting the environment variable UseHardwareFloats to false.

Another way to prevent it is to use an input Vector whose datatype is not 'anything'. For example, it could be 'algebraic'. That's more effort to concoct, and doesn't allow for your pretty 2D Input form of the Vector. I hardly ever see this done.

restart

50/3.(Vector(2, {(1) = .72, (2) = 0.6e-1})); lprint(%)

Vector[column](2, {1 = HFloat(12.0000000024000002), 2 = HFloat(1.00000000020000002)}, datatype = float[8], storage = rectangular, order = Fortran_order, shape = [])

50/3*.72

12.00000000

50/3*0.6e-1

1.000000000

HFloat(0.72)*HFloat(50.*(1/3)); lprint(%)

HFloat(12.0000000024000002)

HFloat(0.06)*HFloat(50.*(1/3)); lprint(%)

HFloat(1.00000000020000002)

restart

UseHardwareFloats := false

50/3.(Vector(2, {(1) = .72, (2) = 0.6e-1})); lprint(%)

Vector[column](2, {1 = 12.00000000, 2 = 1.000000000}, datatype = sfloat, storage = rectangular, order = Fortran_order, shape = [])

50/3*.72

12.00000000

50/3*0.6e-1

1.000000000

HFloat(0.72)*HFloat(50.*(1/3)); lprint(%)

12.00000000

HFloat(0.06)*HFloat(50.*(1/3)); lprint(%)

1.000000000

restart

50/3.Vector(Vector(2, {(1) = .72, (2) = 0.6e-1}), datatype = algebraic); lprint(%)

Vector[column](2, {1 = 12.00000000, 2 = 1.000000000}, datatype = algebraic, storage = rectangular, order = Fortran_order, shape = [])

``

Download testLA_ac.mw

note: I removed your Numeric formatting of output. I'll add that forcing 20 digits of display for scalar results that return with only default Digits=10 decimal digits is like forcing an untruth, and somewhat obscures what's going on.

@mogi Does this do what you want, for your followup example?

[edit] I'm not sure that I understand your syntax. Couldn't you express it in words?

For a given value of d are you trying to use the maximal value that the expression takes for in a=0..1, or are you trying to use the value of a in 0..1 at which that maximum attains? Or are you trying to compute some else?

Here I use the value of a in 0..1 at which the maximum of the expression attains.

restart;

expr := exp(-d*a^2) - 1/3*d*(2*a^3 - 3*a^2 + 1):

#plot3d(expr,d=2..3,a=0..1);

obj := dd -> 1 - eval(a,Optimization:-Maximize(eval(expr,d=dd),a=0..1,
                                              method=branchandbound)[2]):

plot(obj, 0..10, size=[500,300]);

 

Download plot_max.mw

And here I use maximum value which the expression attains for a in 0..1.

restart;

expr := exp(-d*a^2) - 1/3*d*(2*a^3 - 3*a^2 + 1):

obj := dd -> 1 - Optimization:-Maximize(eval(expr,d=dd),a=0..1,
                                        method=branchandbound)[1]:

plot(obj, 0..10, size=[500,300]);

 

Download plot_max2.mw

First 145 146 147 148 149 150 151 Last Page 147 of 336