C_R

3412 Reputation

21 Badges

5 years, 316 days

MaplePrimes Activity


These are replies submitted by C_R

@acer 

Best: better than a sequence of two commands (or your nested version). I was hoping for a single command.

Improve in the sense to include the case sqrt(m*something)/m^-1 when combine,radical,symbolic is called (altough I try to avoid the symbolic option).

Thumbs up for including the m>0 as a relation for solve instead of adding an assumption to the command (what I tried)! This makes totally sense. I will leave the question open why the assume facilty does not do it automatically. I assume that there will be too many exceptions to deal with in the R^n space.

Many thanks!

@ecterrab 

Very nice feature! Is it possible to make it work with ODESteps?

arbconst_with_ODESteps.mw

@Carl Love 

I wrote an addendum under my reply  "No ranges or assumptions".

I hope that fixes my hasty deletion.

@Carl Love 

Thank you for clarifiying. I overlooked the extra dot. I will delete my reply. There is nothing to investigate.

@jediknight 

I cannot fully reproduce the output of your code snippets (see attached). Consider the upload option (green arrow in the editor if you hit reply) if you want others reproduce what you observe.
Have you tried using maximize without ranges or appropriate assumptions? It might work with your version.

maximize seems to have troubles with the expression of GainQ1 in combination with the ranges you provided also in Maple 22

snippets_recap.mw

Update (after deletion of reply):

Maximize has no troubles. It correctly calculated Top_of_Q1 for degenrated ranges.
The deleted file with my wrong interpretation of the ranges from my side for completeness  maximize_wrong_maximum.mw
 

@jediknight
This assignment is causing the problem wx:=solve(GainQ1=Top_of_Q1);

Each time you execute this line

     Top_of_Q1:=eval(maximize(GainQ1),wx=0.1..2);wx:=solve(GainQ1=Top_of_Q1);

GainQ1 changes. This changes Top_of_Q1 which changes wx. And so on...

Here is an alternative way Maple offers without assignments (i.e. `:=`), where you get an equation for wx(Top_of_Q1). Using this way you will hardly run into errors related to unintened assignments.

 

GainQ1 = 8*wx^2*(m-1)/(Pi^2*sqrt((m*wx^2-1)^2+Q1^2*wx^2*(wx^2-1)^2*(m-1)^2))

GainQ1 = 8*wx^2*(m-1)/(Pi^2*((m*wx^2-1)^2+Q1^2*wx^2*(wx^2-1)^2*(m-1)^2)^(1/2))

(1)

params := m = 6.3, Q1 = 1

m = 6.3, Q1 = 1

(2)

subs(params, GainQ1 = 8*wx^2*(m-1)/(Pi^2*((m*wx^2-1)^2+Q1^2*wx^2*(wx^2-1)^2*(m-1)^2)^(1/2)))

GainQ1 = 4.296018185*wx^2/((6.3*wx^2-1)^2+28.09*wx^2*(wx^2-1)^2)^(1/2)

(3)

plot(rhs(GainQ1 = 4.296018185*wx^2/((6.3*wx^2-1)^2+28.09*wx^2*(wx^2-1)^2)^(1/2)), wx = .2 .. 2, axes = boxed, thickness = 5, axis[1] = [mode = log], title = `Gain (w, Q, m)`)

 

Top_of_Q1 = maximize(rhs(GainQ1 = 4.296018185*wx^2/((6.3*wx^2-1)^2+28.09*wx^2*(wx^2-1)^2)^(1/2)))

Top_of_Q1 = .8281966930

(4)

subs(GainQ1 = Top_of_Q1, Top_of_Q1 = .8281966930, GainQ1 = 4.296018185*wx^2/((6.3*wx^2-1)^2+28.09*wx^2*(wx^2-1)^2)^(1/2)); solve(%, {wx})

{wx = -.8945713660-0.1334178082e-4*I}, {wx = .8945713660+0.1334178082e-4*I}, {wx = -.8945713660+0.1334178082e-4*I}, {wx = .8945713660-0.1334178082e-4*I}

(5)

For numerical reasons, the solutions are complex. Alternatively you can use fsolve but an "error term" has to be added to get a real valued solution

subs(GainQ1 = Top_of_Q1, Top_of_Q1 = .8281966930, GainQ1 = 4.296018185*wx^2/((6.3*wx^2-1)^2+28.09*wx^2*(wx^2-1)^2)^(1/2)); fsolve((rhs-lhs)(%)+0.1e-5, {wx = .2 .. 2})

{wx = .8938364815}

(6)

Or use:

Optimization[Maximize](rhs(GainQ1 = 4.296018185*wx^2/((6.3*wx^2-1)^2+28.09*wx^2*(wx^2-1)^2)^(1/2)))

[.828196692670812418, [wx = HFloat(0.8945713660947568)]]

(7)

NULL

 

Download WO_assignment.mw

@Joe Riel 

Including a code optimization option in the custom component template (and making the intermediate variables disappear in the parameter pane) would be much more convenient than my separate Maple worksheet or inserting the commands into the template. Also, every user of a custom component could benefit from code optimization without having to learn the required Maple commands.

I would definitely use it!

@acer

If its by design, I will make the type specification my default. In my example the value of la is smaller than 0.5 which leads to errors of 50% and more (red C code vs Maple code in green).

By the way, codegen also has an undocumented design “feature”. When codegen is used in my original worksheet instead of CodeGeneration, the parameters defined as outputs appear as “passed by reference” in the C code. This works also with other names than outputs. Very handy. With CodeGeneration[C], “passed by referenced” must defined manually. (Since codegen is deprecated I will not ask, how codegen magically predicts what the outputs are.)

Thank you for the clarification!

@acer 

Sorry for the confusion.  

I found the type double as a synonym for float[8] here: help(type, float[8]). If the parser replaces it with float[8] I don't see a problem (if...).

The comment is more of a personal note. I meant: Type definition to double was added to get all parameters defined as double in the C code output of a subsequent call to CodeGeneration.

What is still not clear to me:

In the equation list there is one equation (t54 = 1 + 200 * la) that can be interpreted as integer relation. This could be the reason why CodeGeneration defines “t54” and “la” as int.

What I just tried: When this equation is inserted into an evalf call, "t54" and "la" are defined as double in the C code (without requiring your solution).

codegen neither requires your solution nor evalf workarounds (which make the code less clean).

With these observations I would ask now: Is this (assumed) interpretation of such equations a design feature or something unintended (i.e., something that should be reported)?

@acer 

A perfect oneliner leaving even space for a "why comment"

codegen[makeproc](TheList, parameters = map(`::`, [proc_params], double));# double required because CodeGeneration[C] sometimes puts int instead of double.

Since codegen[C] did not show this effect: Do you think its worth bringing this difference to the attention of Maplesoft?

Thank you!

 

Visual Studio Community 2017 and 2019 replace the Express Edition.

A bit hidden when following the download link in help(Setup, Compiler):

On the MS download pages: There is no download link to Visual Studio Community 2017. Installing another 2017 download, will list the Community package under the Available tab in the Visual Studio Installer.  

Desktop development with C++ must be installed additionally (available under the Workloads tab of the package).

These are the new paths:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsx86_amd64.bat

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsx86_amd64.bat

@tomleslie 

Before asking I consulted indets and type\structure (where indets points to). In the later I could not find an appropriate match. That’s where I stopped.

I should have gone to the type help page (referenced by type\structure) and browsed through the more than 250 (!!!) types. I'm not sure I would have recognized suffix on the first go, since this word had no meaning in my life (so far).

That’s why I consider nm`s answer the closest in my reach.

The help page of type\structure is quite intimidating for someone who only knows "normal" types of programming languages. This rich choice of types reminds me of the concept of function, which is used much more narrowly in engineering than in mathematics. Acer has made some efforts to introduce me to this level of abstraction.

The type command and its uses is another good example that Maple is not a programming language.

Thank you for taking your time!

@acer

I was not aware of that (implication by the choice of a command). Now it makes sense.

The alternative for the (undocumented?) `if` call is indeed intersting.

Thank you for these insights!

@Carl Love @nm @tomleslie

These are all excellent answers!

It's difficult to pick a winner.

nm answer uses commands that can be found in the help system.

That suffixed can be used as a command without "type" suprises. From the help system I can deduce at most a use like this

            select(X -> `if`(type(X, 'suffixed(t, integer)'), true, false), lst)

(I assume that Carls &under is required for other structures than sets.)

Thanks allot!!!

@Joe Riel @Thomas Richard 

Here is an update what I could figure out:

  • ExternalCCodeGen I was refering to is actually not an old Maple command as I assumed, but a procedure written by the author of the video. A call to CodeGeneration (to create a C code string) and to FileTools[Text][WriteFile] (to write the string to a file) could be used for a replacement of ExternalCCodeGen.
  • Much simpler to save is Thomas solution.
  • Saving is also possible with the External C/Library Block App and the option “Text Area”. In the text area: copy&paste Maple Output of C code -> optionally modify -> save file.

Using C code in MapleSim with the External C/Library Block App requires customizing the generated code to definitions (#define) and parameters accepted by the App. Knowledge of C is needed for that.

First 56 57 58 59 60 61 62 Last Page 58 of 67