acer

32490 Reputation

29 Badges

20 years, 8 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@DanielRe Here is a minor revision which utilizes uses statements within the procedure bodies, instead of calling with at the top level (or calling with inside the procedures, as in your original, which is problematic).

GaußKronrodQuadraturFehlerbehandlung_ac2.mw

I had another look at plots:-dualaxisplot, and noticed that it doesn't seem to allow the two vertical axes to get their own separate legends, using separate legendstyle and location options. I find that a pity, since it is often not obvious which curve relates to which vertical axis. The earlier worksheet I uploaded used two vertical axis labels, which corresponded to the two legend items, whose colored lines corresponded to the two colored curves. But that requires one's sight to bounce between three things, which I find suboptimal. Here's one example:

In this new attachment I've tried to use a color shading of the vertical axes, and axes labels, to get a visual cue that only requires switching one's sight between two things.

This is basic programming. If you've written several hundred lines of code without organizing the flow by using procedures, and you want it to be re-usable in the sense of varying parameter values, then you've gone wrong.

That's true in every effective modern programming language, not just Maple (though the implementation and naming of "procedure" varies, of course).

Once the code is organized well it should be straightforward to re-use it like you want.

It is not very helpful to not supply the code in an uploaded worksheet here. A few hundred lines is not long.

(ps. I am not trying to sound harsh. This is not a rare situation. And with the material provided there's a good chance that you can get help with it.)

You've forgotten to show the examples of calling your procedure. You didn't show us what its argument would be.

Look, upload a worksheet that provides all the code to reproduce both plots of which you write. Use the green up-arrow in the Mapleprimes editor to upload (and don't forget to actually Insert it from the popup dialog, and click its OK button).

You should not call with from within a proc. It'd be better to have your procedure return an expression sequence of both plots, instead of printing them.

@mehdi jafari What is wrong is that your syntax is incorrect. Here is the call to int from your second example.

'int((exp(-32.74123792568-0.8916456579806e-1*ln(4.852623952*10^9*v^2)), numeric)
     *exp(-v^2/(2*T))*v^3, v = 2 .. 100)';

int((exp(-32.74123792568-0.8916456579806e-1*ln(4852623952.*v^2)), numeric)*exp(-(1/2)*v^2/T)*v^3, v = 2 .. 100)

 

The integrand that you entered has an expression sequence multiplied by a call to exp. What is that supposed to mean?

You write that you, "put numeric option in the middle of the integration". Do you really believe that putting an option word in the middle of a multiplication, as part of an expression sequence, makes sense?

The expression sequence is done in by `simplify`, where simplify((a,b)*c) returns a*c. I might call that GIGO.

How could the integral be computed numerically with the integrand depending on the unassigned name T?

How do the expressions for assigned to M, Mc, Nc, V, and Vc contribute? Were they used for the procedures H,L,G,K? It might help us, if you made your process more clear. Don't ever copy & paste. How did you arrive at the expressions inside thse procedures? Are you sure that those procedures' are correct, and you didn't omit anything (like plus signs for addition, etc)?

Have you tried using rationals instead of floats like 0.5?  How about using evalc, Re, and Im (perhaps on numerators and denominators of the longer combinations) and do simplification? It may benefit. And then you could consider writing it as a larger DE.

I suggest that you uses Tools->Options from the main menubar and change the following pair of related GUI preferences:

 - Under the Display tab, change the drop-menu item Input display to Maple Notation for input (ie. 1D plaintext) instead of 2D Math Notation (ie. marked up typeset math, aka 2D Input)

 - Under the Interface tab, change the Default format for new worksheets to Worksheet (ie. execution groups, which should seem more familiar) instead of Document (ie. paragraphs and document blocks).

Then hit the Apply Globally button in the popup dialog.

There have been many reports over the years on this site of users tripping up on 2D Input, partly because it's buggy and partly because it's not WYSIWYG. Really , they are two different languages, with different parsing rules, bugs aside. Having a space denote multiplication implicitly is a common issue. It's even worse if you get implicit multiplication without a visible space.

Adjusting the two preferences above makes the Java GUI behave more like the old (Classic) GUI from pre-2000.

@Rariusz Ok thanks. I am hoping that by also utilizing a smoothing of the diff(theta(t),t) data I can get an even better fit to the theta(t) data. By this I mean a weighting in the objective, for the raw theta(t) data alongside smoothed diff(theta(t),t) data.

I'll let you know when I get to report something. Perhaps tomorrow.

I still think that it might help significantly to know a ballpark for the frequency of the simulated i(t). In the absence of such knowledge I may try using an additional, moderate penalty against a higher frequency i(t).

@Rariusz Thank you. I hope that you can understand why your latest reponse contains the details which ought to have been provided originally.

As is not uncommon for such kinds of nonlinear optimization problem with an oscillatory aspect, there are many local minima which are "close" to globally optimal for some reasonable objective metrics. That might be a problem.

So, in just a few minutes a worksheet of mine produces a similar plot for ode_x2 which compares quite closely to your simulation, for a fit to the theta(t) data from the third column. It uses a continuous approximation for V(t) using the data from the second column. It took me about 15 minutes to write.

But... depending on the run, and depending on the ranges I supply for the parameters, I can get several sets of results for the parameters. All produce a reasonable fit (plot) for the simulation of theta(t) and diff(theta(t),t). But the frequency of oscillation of the simulated i(t) varies a great deal, from slow to very fast.

If there is some physical reason (constraints on the motor design, etc) why a low/medium/high frequency of oscillation is needed for the simulated i(t) , or some tighter ranges for the parameters, then now would be a great time to mention it.

Additionally, it's not clear whether you need to match the highly/fast varying data for diff(theta(t),t) with a highly varying/fast simulation of that dependent quantity, or whether you would be satisfied with a a simulation that approximated a smoothed curve of that data (fourth column).

What kinds of entries does the Matrix have? (eg. floats, integers, rationals, symbolic expressions?)

For floating-point entries, done right, it can take about a second (depending on your machine, of course) at hardware double precision.

How fast do you need it to be? How accurate? Is the Matrix dense?

ps. A 600-by-600 Matrix is 2-dimensional, and not "high-dimension". It is not small, but it has only two dimensions.

@Kitonum This person has not yet figured out how to tell us which old version he's using, despite posting many questions on this site where the version affects the answer.

I'm trying to get this straight, and sorry if I'm being dense.

Is this right:
 - The second column represents values for V(t) at the corresponding data values
    in the first column (ie, t). An interpolating function formed from these data values
    could be used as a known function in the dsolve call (where the OP originally has just V).
 - The goal is the find values for parameters J,b,K,R,L such that the numeric
    dsolve solution procedure assigned to ode_x2 will fit the data values in the third
    column (ie, theta(t)).

If that is correct, then what does the i(t) (for which a procedure in the dsolve return is assigned by the OP to ode_x1) represent, and does it correspond to anything in the supplied data? Is there some quantitaive or qualitative goal for ode_x1 at the optimal parameter values?

Is the fourth column of data supposed to come into the objective function (eg, fit to the diff(theta(t),t) from the dsolve procedure, by contributing to the objective)?

What are permissible ranges for the five parameters?

@radaar If you change the assignment to y:=copy(x) and add return y as a new last statement then you don't get the result you showed. sigma_ac2.mw

If you simply add a new last statement return copy(y) , and leave the assignment y:=x as it was originally, then you get the results you showed. sigma_ac1.mw

The distinction is in whether you want the ensuing min/max examination and replacement to take place on the copy of x, or to be done in-place on x itself.

@Mac Dude The case of a literal float multiplied by Pi, under an evalf call, seems like the odd man out to me.

I am not a fan of kernelopts(floatPi=true) , but I can understand how/why the other cases below behave as they do. It's a tricky business, though, and if there are additional subtleties to its behavior then that ought to be fully documented.

restart;

kernelopts(version);

`Maple 2018.0, X86 64 LINUX, Mar 9 2018, Build ID 1298750`

#
# This is the "new" floatPi behavior.
# It is (at least) comprehensible, even if
# not to everyone's taste.
#
restart;
kernelopts(floatPi=true): # default
Pi*704.0;

2211.681228

restart;
kernelopts(floatPi=false):
Pi*704.0;

704.0*Pi

#
# This is "new" floatPi behavior, together
# with normal evaluation rules for procedure
# calls (arguments evaluated up front).
#
restart;
kernelopts(floatPi=true):
trace(sin):
sin(Pi*704.0);

execute sin, args = 2211.681228
{--> enter sin, args = 2211.681228
<-- exit sin (now at top level) = -0.1272144399e-6}

-0.1272144399e-6

restart;
kernelopts(floatPi=false):
trace(sin):
sin(Pi*704.0);

execute sin, args = 704.0*Pi
{--> enter sin, args = 704.0*Pi

704.0

0.

0

0

<-- exit sin (now at top level) = 0}

0

#
# Since `evalf` has special-evaluation rules it can delay
# the evaluation of Pi*Q and do what it wants before passing
# as argument to `sin`.
#
restart;
kernelopts(floatPi=true):
trace(sin):
Q := 704.0:
evalf(sin(Pi*Q));

execute sin, args = 2211.681228
{--> enter sin, args = 2211.681228
<-- exit sin (now at top level) = -0.1272144399e-6}

-0.1272144399e-6

restart;
kernelopts(floatPi=false):
trace(sin):
Q := 704.0:
evalf(sin(Pi*Q));

execute sin, args = 704.0*Pi
{--> enter sin, args = 704.0*Pi

704.0

0.

0

0

<-- exit sin (now at top level) = 0}

0.

#
# Using % for the float gets behavior like with an
# assigned name.
#
restart;
kernelopts(floatPi=true):
trace(sin):
704.0:
evalf(sin(Pi*%));

execute sin, args = 2211.681228
{--> enter sin, args = 2211.681228
<-- exit sin (now at top level) = -0.1272144399e-6}

-0.1272144399e-6

#
# But now, with a literal float instead of the assigned
# `Q`, there seems to be no floatPi effect.
#
# This is the interesting case.
#
restart;
kernelopts(floatPi=true):
trace(sin):
evalf(sin(Pi*704.0));

execute sin, args = 704.0*Pi
{--> enter sin, args = 704.0*Pi

704.0

0.

0

0

<-- exit sin (now at top level) = 0}

0.

 

Download floatPi_anomaly.mw

So using an Equation Label seems to get the behavior like for a literal float (differing from that of an assigned name or %).

Let's try and narrow down the interesting case, which seems to be the case of a function call made under evalf. In other cases there is behavior similar to automatic simplification.

kernelopts(version);

`Maple 2018.0, X86 64 LINUX, Mar 9 2018, Build ID 1298750`

restart;
kernelopts(floatPi=true):
kernelopts(floatPi);
704.0*Pi;

true

2211.681228

#
# Like automatic simplification
#
restart;
kernelopts(floatPi=true):
kernelopts(floatPi);
'704.0*Pi';

true

2211.681228

restart;
kernelopts(floatPi=true):
kernelopts(floatPi);
f('704.0*3');
f('704.0*Pi');

true

f(2112.0)

f(2211.681228)

restart;
kernelopts(floatPi=true):
kernelopts(floatPi);
evalf(f('704.0*3'));
evalf(f('704.0*Pi'));  # ???

true

f(2112.0)

f(704.0*Pi)

restart;
kernelopts(floatPi=true):
kernelopts(floatPi);
f:=proc() return eval(args[1], 1); end proc:
trace(f);
evalf(f('704.0*3'));
evalf(f('704.0*Pi')); # ???

true

f

{--> enter f, args = 2112.0
<-- exit f (now at top level) = 2112.0}

2112.0

{--> enter f, args = 704.0*Pi
<-- exit f (now at top level) = 704.0*Pi}

2211.681228

 

Download more_floatPi.mw

I have been careful to put a forcing, explicit call like kernelopts(floatPi=truefalse) after each restart above, to ensure that it was being explicitly set each time. The default is supposed to be true. But I found the following, which I wanted to side-step,


 

restart;

kernelopts(floatPi=true):
kernelopts(floatPi);

true

kernelopts(inline=true):
kernelopts(inline);

true

kernelopts(assertlevel=0):
kernelopts(assertlevel);

0

restart;

kernelopts(floatPi=false):
kernelopts(floatPi);

false

kernelopts(inline=false):
kernelopts(inline);

false

kernelopts(assertlevel=1):
kernelopts(assertlevel);

1

restart;

kernelopts(floatPi); # not reset to default!?

false

kernelopts(inline); # reset to default, true

true

kernelopts(assertlevel); # reset to default, 0

0

 

Download kernelopts_anomaly.mw

@Joe Riel Not all readers will know the difference between loading from Library Archive (executing export ModuleLoad if a module, scanning archives for the name and adjusting permanent store) and executing a call to with (thus rebinding names of exports, if a module).

So the term "load" is somewhat ambiguous. And the subtle distinctions might be relevant.

Loading a module package, eg. by referencing the name of an export (triggering loading from Archive, and thence execution of its Moduleload), can occur even without calling with.

It'd be extra effort, but it might help clarify the issues if you used terms with strict definitions, or a glossary.

Just a thought.

First 234 235 236 237 238 239 240 Last Page 236 of 594