acer

32333 Reputation

29 Badges

19 years, 320 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@Jak So just use the red curve(s), and not the blue curve(s).

The red is for eq1=0, and the blue is for eq2=0.

They already (each) have a line style (dash, solid) that changes when eq1<eq2 or not.

I threw both the red and the blue. It is trivial to exclude either in the code I gave.

You can also restrict to any particular quadrant -- just specify the ranges and/or view.

For example, also using an alternate approach with an explicit solve, instead of an implicit plot, for eq1=0. You may wish to treat x[u]=0 specially, or exclude it, say with the view. I used a style dot instead of dash. Adjust as desired.

restart;

with(plots): with(plottools,transform):

r:=0.927: K:=1.8182*10^8:d[v]:=0.0038:d[u]:=2: delta:=1: p[m]:=2.5:
M:=10^4: p[e]:=0.4: d[e]:=0.1: d[t]:=5*10^(-9): omega:=2.042: b:=1000:
h[e]:=1000:h[u]:=1:h[v]:=10^4:

eq1 := r*d[t]*h[e]*x[u]^3+(r*h[e]*(-K*d[t]+d[t]*h[v]+d[e])
+r*p[e]*x[m])*x[u]^2+(r*h[e]*(-K*d[t]*h[v]-K*d[e]+d[e]*h[v])
+K*p[e]*(d[u]-r)*x[m])*x[u]-r*K*h[e]*d[e]*h[v]:

eq2 := (d[t]*x[u]+d[e])*(2*r*x[u]/K+d[u]*p[e]*x[m]*x[u]/((h[v]+x[u])
*(d[t]*x[u]+d[e])*(h[e]+p[e]*x[m]*x[u]/((h[v]+x[u])*(d[t]*x[u]+d[e]))))-r)
+d[u]*h[e]*x[u]*(p[e]*h[v]*x[m]/(h[v]+x[u])^2-d[t]*p[e]*x[m]*x[u]/((h[v]+x[u])
*(d[t]*x[u]+d[e])))/(h[e]+p[e]*x[m]*x[u]/((h[v]+x[u])*(d[t]*x[u]+d[e])))^2:

Digits:=40:

TL:=transform(proc(a,b)
                `if`(evalf(eval(eq1<eq2,[x[m]=a,x[u]=b])),
                     [a,b],[undefined,undefined]); end proc):
TU:=transform(proc(a,b)
                `if`(evalf(eval(eq1>=eq2,[x[m]=a,x[u]=b])),
                          [a,b],[undefined,undefined]); end proc):

P1:=implicitplot(eq1=0, x[m]=-1e3..1e3, x[u]=-3e8..3e8,
                 color=red, thickness=3,
                 grid=[151,51], gridrefine=0, crossingrefine=0):
PC:=display(TL(P1),
            display(TU(P1),overrideoption,linestyle=dot),
            labels=[x[n],x[u]], size=[400,400]):
PC;

display(transform((a,b)->[b,a])(PC),
        view=[0..2e8,0..500],
        labels=[x[u],x[m]], size=[400,400]);

P1:=plot([solve(eq1,x[u])],x[m]=0..460,color=red,thickness=3,adaptive=false,numpoints=1000):
PC:=display(TL(P1),
            display(TU(P1),overrideoption,linestyle=dot),
            labels=[x[n],x[u]], size=[400,400]):
PC;

display(transform((a,b)->[b,a])(PC),
        view=[0..2e8,0..500],
        labels=[x[u],x[m]], size=[400,400]);

 

Download eq1eq2_rev2.mw

@Jak I don't understand what you're saying, sorry.

In what I showed the red curve denotes eq1=0 and the blue curve denotes eq2=0, and their linestyle is solid when eq1<eq2 and dashed otherwise.

Could you explain more explicitly how that is not what you requested?

Is it just that you want the two linestyles reversed in purpose? That's a simple edit to the code I gave -- by just switching the instances of the linestyle override. eq1eq2_rev.mw 

Such a flip produces these:

The cube of the rhs of the first equation is not equal to the rhs of the second equation, so are you sure that you have transcribed it correctly?

You had them as,

  y = (sqrt(x) + 10)^(1/3) - (sqrt(x) - 10)^(1/3);

and

  y^3 = 20 - 3*(x - 100)^(2/3);

[edit] As member vv has observed, you may have written down the second equation wrongly, and intended to have written it instead as,

   y^3 = 20 - 3*(x - 100)^(1/3)*y;

Have you considered uploading and attaching a worksheet that reproduces your problem?

Attach the original document that contains all the relevant definitions (i(t), delta, sol4, and so on).

@gawati2611 Your example was exp(w*x*I) and you stated that x and w should be real-valued, and that you'd want the height to be taken as the modulus.

abs(exp(w*x*I)) assuming x::real, w::real;
                 1

evalc(abs(exp(w*x*I)));
                 1

(I mentioned this earlier, in my original Comment, for the very reason that I wanted to check with you that you understood this.)

You could contact Maplesoft Technical Support about this.

The OP also asked about floating-point error and using the Optimization package.

There is no general facility in that package for estimating quantity of the floating-point error, but there are options for controlling (bounding it). Depending on the method, there are options for specifying a tolerance for optimaility of the objective as well as a tolerance for maximal, absolute constraint violation. (See the Help pages.)

Apart from specifying those tolerances, you can also get additional printing of what value gets used for them (either specified, or as defaults).

Note that actual results may be more accurate (ie. smaller error) than the tolerance -- which is meant to serve as a bound, not an estimate.

Note that additional working precision (Digits) may be required in order to ensure that the tolerances are not met accidentally (wrongly) due to numeric round-off error.

Note that there may be a hard limit (16?) on the number of major iterations for some methods.

restart;

obj:=(x-2*y)/(5*x^2-2*x*y+2*y^2);
cond:=2*x^2-y^2+x*y=1;

(x-2*y)/(5*x^2-2*x*y+2*y^2)

2*x^2+x*y-y^2 = 1

infolevel[Optimization]:=6:

Digits:=10:  # default
fsol1:=Optimization:-Maximize(obj, {cond});
evalf[10]( sqrt(2)/4 - fsol1[1] );

NLPSolve: calling NLP solver

NLPSolve: using method=sqp

NLPSolve: number of problem variables 2

NLPSolve: number of nonlinear inequality constraints 0

NLPSolve: number of nonlinear equality constraints 1

NLPSolve: number of general linear constraints 0

NLPSolve: feasibility tolerance set to 0.1053671213e-7

NLPSolve: optimality tolerance set to 0.3256082241e-11

NLPSolve: iteration limit set to 50

NLPSolve: infinite bound set to 0.10e21

NLPSolve: trying evalhf mode

attemptsolution: number of major iterations taken 14

[.353553390593275063, [x = HFloat(0.8164965809123527), y = HFloat(-0.29885849069043535)]]

-0.1e-9

Digits:=24:
fsol2:=Optimization:-Maximize(obj, {cond});
evalf[24]( sqrt(2)/4 - fsol2[1] );

NLPSolve: calling NLP solver

NLPSolve: using method=sqp

NLPSolve: number of problem variables 2

NLPSolve: number of nonlinear inequality constraints 0

NLPSolve: number of nonlinear equality constraints 1

NLPSolve: number of general linear constraints 0

NLPSolve: feasibility tolerance set to 0.1e-11

NLPSolve: optimality tolerance set to 0.5248074602e-17

NLPSolve: iteration limit set to 50

NLPSolve: infinite bound set to 0.10e21

NLPSolve: trying evalf mode

attemptsolution: number of major iterations taken 15

[.353553390593273762200610, [x = .816496580927725973393146, y = -.298858490722684383537048]]

-0.188e-21

Digits:=30:
fsol3:=Optimization:-Maximize((x-2*y)/(5*x^2-2*x*y+2*y^2), {2*x^2 - y^2 + x*y=1},
                        optimalitytolerance=1e-29, feasibilitytolerance=1e-29,
                        iterationlimit=16);
evalf[30]( sqrt(2)/4 - fsol3[1] );

NLPSolve: calling NLP solver

NLPSolve: using method=sqp

NLPSolve: number of problem variables 2

NLPSolve: number of nonlinear inequality constraints 0

NLPSolve: number of nonlinear equality constraints 1

NLPSolve: number of general linear constraints 0

NLPSolve: feasibility tolerance set to 0.1e-28

NLPSolve: optimality tolerance set to 0.1e-28

NLPSolve: iteration limit set to 16

NLPSolve: infinite bound set to 0.10e21

NLPSolve: trying evalf mode

attemptsolution: number of major iterations taken 16

[.353553390593273762200422181053, [x = .816496580927726032732427201246, y = -.298858490722684508034628621562]]

-0.1e-29

 

Download Opt_userinfo.mw

@Anthrazit When you load one of the Unit computational environments (Units:-Simple, Units:-Standard) it rebinds various commands (`+`, `*`, etc) to the respective package exports which also combine the units of the results.

By combining the units I mean that the units get converted to the standard or base units for the given system (eg, SI). Thus 10*millimeter+4.0*meter produces 4.01*m, etc.

That affects computations done that explicitly utilize those commands. For example, computations done at the top-level are such explcit calls.

(**) But loading the package does not change such computations (even arithmetic) with units inside most (almost all) procedures that are part of the main Maple Library (.mla of interpreted procedures). Loading the Units package by the with command rebinds the command names but it does not reassign the global command names.

That is why arithmetic that happens during Matrix addition does not combine the units.

That is why you might also want to call combine(...,units) on scalar results, or map that across Matrix/Vector/Array results.

By the way, the distinction I made in paragraph (**) above affects all packages which rebind names of exports. For user-authored packages an alternative is sometimes to use objects which have their own static methods (keyed upon global command names, for example). But Units have not been re-implemented as objects, and it is tricky to do so robustly.

note. Earlier I had been under the impression that you already knew these further points, which is why I have limit myself to addressing deeply only the matter of the multiple, distinct, local unit symbols in your result. The business with the multiple local symbols is an unusual and rare quirk (and a bug that I reported), whereas this further business of combining units is more common and (for better or worse) part of the current Units design.

@mmcdara (I suspect you meant to address Carl -- who responded -- and not me.)

You might have a look at the extension Help page.

What kind of plot do you want to obtain? Please be specific.

Do you want a 3D plot were the modulus and argument are used to get (say) the height and shading color respectively? (Or, even a 2D plot since the modulus in a particular example may simplify to just 1.)

Do you want a 2D density plot where the modulus and argument are used to get (say) the intensity and hue respectively? (Again, the modulus may simplify to just 1 for a particular example.) Or some kind of contour plot?

@Anthrazit The Programming Guide has some examples (eg. of modules, and procedures, and  packages).

I am happy to make the edits I mentioned later this weekend (and a workaround for your issue). I just wanted to make sure that it would be OK with your ongoing project if I altered the programming style in such ways.

@Carl Love The original won't work in Maple 2020.1 in pasted into a 2D Input region.

But, the revision does. conf_2dmath.mw

@Anthrazit It is not good programming to initialize with all those calls to with, prior to defining all the procedures. It would be better to utilize fully qualified calls (eg, Units:-UseUnit, etc) in the places that need them, or to utilize the uses facility in the procedures in a case-by-case, by-necessity fashion.

It would also be better programming technique to create a parent module for the procedures, so that they can share key variables' values (lg, etc) without them being declared and assigned as globals.

I can fix the problem with the "duplicate" units (un-combined), but I feel that there's less long-term and robust merit in addressing the Units (and Units:-Simple) difficulties unless the programming methodology is overhauled for the points I've mentioned.

 

@Anthrazit I think that I understand now. It always worked for me, with the various ways of re-executing the whole sheet, extending and re-extending, etc. I'm using Maple 2020.1 for 64bit Linux.

First 164 165 166 167 168 169 170 Last Page 166 of 591