acer

30635 Reputation

29 Badges

18 years, 345 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@C_R Fwiw, I submitted a bug report related to this a few years ago.

The assignment,

    aS := -i/n;

makes no sense in that context, with no numeric value ever given for that `i`.

The x-coordinates of points S and C depend on aS, so of course geometry:-draw cannot handle them, since `i` has no value.

You asked, "How to correct this procedure?" The first thing to do is explain what you're trying to do.

@Ronan The is command will return FAIL when it is not able to ascertain whether the result is true or false. That could happen if the expression is too complicated (...think of complicated radicals of symbolic subexpressions, in numerator and denominator, etc). Or it could happen unless certain key assumptions were provided. And so on.

I don't know what kinds of expressions you'll encounter, so I don't know whether this situation is even likely here. If it is likely then it matters whether you would rather risk false positives or false negatives (or, throw an error). If you'd be ok with a false negative (eg. something very complicated isn't correctly identified as being mathematically equivalent to 1, and so it taken to not be 1) then no adjustment is needed.

@janhardo If I add it with the `true` as last argument to AddMet then it does get used and work. See the verbose printout. Of course I commented out the test-line to remove it, after adding it.

But your BestSimp routine is not returning the result with shortest value (LeafCount metric). I leave that for you.

fullSimplify_module_-metoden_toevoegen_werkt_ws_uitzoeken_forum_opmerkingen_corrigeren_A_acc.mw

@janhardo If you assign,

   fn := eval(parse(cat("proc(e) ", method_body, "; end proc")));

then (since procedures have last name evaluation) you'd want something more effective like,

   methods[method_name] := eval(fn);

instead of your,

   methods[method_name] := fn;

in order to add it more usefully to the table.

I am not a fan of passing/parsing a string, but here is that last worksheet, edited:
fullSimplify_module_-metoden_toevoegen_werkt_ws_uitzoeken_forum_opmerkingen_corrigeren_A_ac.mw

@janhardo You have the table `methods` as a local of BestSimp, which makes no sense, since you're trying to access/amend that from other procedures in the parent module of BestSimp.

Your code for a test/check (that it has worked properly) is also faulty.

Using globals in the other procs isn't the way to fix that. Using globals is also very poor programming for this (even if you altered the code to use it consistently). You have already got a module; you should utilize that fact, with a Record or table.

You don't need to inline the whole attachment here, each time.

@janhardo I don't see an attachment with a list named methoden, and so it's not clear what "worksheet" you're now referring to.

I see a table named methods in the module in your last attachment, a worksheet named,
   Module_fullSimplify-2_commands_MPforum.mw
but the paremeters of that module's export AddMet does not match your subsequent query about calling it like,
   AddMethod("TEST(e,trig)", proc(e) return TEST(e,trig); end proc);

Look again at your Reply in which you asked about this. It has no worksheet attachment. All it contains is the following -- which is why I responded using its very same format of arguments:

How to get the TEST methode name into the list methoden ?
The methoden list has more names in it.

AddMethod("TEST(e,trig)", proc(e) return TEST(e,trig); end proc);


methoden := [
        "CompleteSquareSteps(e)" = proc(e) return CompleteSquareSteps(e); end proc,
        "TEST(e,trig)", proc(e) return TEST(e,trig); end proc
          ];

@janhardo That's what my first block of code shows. I leave it to you to incorporate it into your own module.

note: You mentioned a worksheet containing `methoden`, but never gave it.

@janhardo An example,

restart;

 

M := module()
  local methoden:=["CompleteSquareSteps(e)"=proc(e) return CompleteSquareSteps(e); end proc];
  export AddMethod:=proc(a,b) methoden:=[methoden[],a=b]; NULL; end proc;
  export showmethoden:=proc() map(print,methoden); return NULL; end proc;
end module:

 

M:-showmethoden();

"CompleteSquareSteps(e)" = proc (e) return CompleteSquareSteps(e) end proc

 

M:-AddMethod("TEST(e,trig)", proc(e) return TEST(e,trig); end proc);

 

M:-showmethoden();

"CompleteSquareSteps(e)" = proc (e) return CompleteSquareSteps(e) end proc

"TEST(e,trig)" = proc (e) return TEST(e, trig) end proc

M:-AddMethod("TEST1(e,trig)", proc(e) return TEST2(e,trig); end proc);

 

M:-showmethoden();

"CompleteSquareSteps(e)" = proc (e) return CompleteSquareSteps(e) end proc

"TEST(e,trig)" = proc (e) return TEST(e, trig) end proc

"TEST1(e,trig)" = proc (e) return TEST2(e, trig) end proc


Why not use a table?

restart;

 

M := module()
  local methoden;
  methoden["CompleteSquareSteps(e)"]:=proc(e) return CompleteSquareSteps(e); end proc;
  export AddMethod:=proc(a,b) methoden[a]:=b; NULL; end proc;
  export showmethoden:=proc() map(print, [indices(methoden,nolist)]); return NULL; end proc;
  export usemethod:=proc(m,ee) if assigned(methoden[m]) then
                                 methoden[m](ee);
                               else error "no such method %1",m;
                               end if; end proc;
end module:

 

M:-showmethoden();

"CompleteSquareSteps(e)"

 

M:-AddMethod("TEST(e,trig)", proc(e) return TEST(e,trig); end proc);

 

M:-showmethoden();

"TEST(e,trig)"

"CompleteSquareSteps(e)"

M:-AddMethod("TEST2(e,trig)", proc(e) return TEST2(e,trig); end proc);

 

M:-showmethoden();

"TEST(e,trig)"

"TEST2(e,trig)"

"CompleteSquareSteps(e)"

M:-usemethod("TEST2(e,trig)", expr);

TEST2(expr, trig)

M:-usemethod("CompleteSquareSteps(e)", expr);

CompleteSquareSteps(expr)

M:-usemethod("foo(e)", expr);

Error, (in usemethod) no such method foo(e)

 

 

Download module_ex.mw

@SUN ZHUOYU 

A few comments, if I may:

1) If your connection is poor then you could remove all output from the worksheet (see menubar) which in this case makes the file much smaller.
2) I also changed how points1 is created (using the last way in my original Answer above), and made some Matrices more directly.
3) Your workseet uses B:=100 to set up the data, and then clobbers that by making B a Matrix. That means you cannot go back to some earlier stages of the code without needing a restart. (One of your screeenshot images looks like you made such a mistake at one time.) It'd be easier if you simply used different/distinct  names for different purposes.
4) the final call to display was misspelled as "dispaly" which is why it didn't produce&render a final plot.

@SUN ZHUOYU The command listplot3d doesn't have dedicated options for specifying the ranges over which the x- and y-axis data are be interpreted.

But the surfdata command offers that.

3D_exact_and_numerical_solution_comparison_ac.mw

@SUN ZHUOYU I'm not going to look at your followup (or any other Question of yours) if you don't upload and attach your actual worksheets.

It is poor etiquette to expect people to manually enter equivalent code based on mere images and screenshots.

More importantly, your image appears to be an incomplete picture of what was going on. It's not clear what is your actual problem or goal.

At the top of your image, what are x[j] and y1[j] supposed to reference? Is it top secret? If you're trying to programmatically construct points1 then show us the complete original worksheets.

@Andiguys Regarding your followup G1.mw worksheet, your constraint C1 requires that Q2 be at least 9.2e7 for sigma=0..3.

There is no possible feasible sigma,Q2 pair satisfying C1, given your ranges sigma=0..3 and Q2=4.0e5..2e7.

ps. The minimum of TRC(sigma,Q2) for sigma=0..3 would occur at sigma=3 and Q2=9.27e7.

pps. You should construct TRC by,
    TRC := unapply(eval(TC1c, DATA),sigma,Q2);
instead of just unapply(...,sigma), so that you can properly call TRC at a pair of values, to check.

You might find using implicitplot useful. (...which I also did here -- extruded to 3D barrier surfaces -- in earlier answers for an earlier model variant you'd posed. You could also do that here.) This followup is not complicated, but if you have trouble understanding it then plots could only help.

G1_ac.mw

Now, could you explain your difficulty in understanding, when constraint C1 is removed? You have sigma=0..3, and if sigma is not negative then the smallest sigma possible in that range (ie. sigma=0) will attain at the minimum of TRC(sigma,Q2) which is given by,
   1.22675e9 + 2.5*Q2 + 3.8e7*sigma
   +700000000*sigma*(0.02 + 2.285714286e-2*sigma)

and Q3 doesn't preclude sigma=0 for your Q2>=4e5.  Notice that sigma only appears in terms of the sum TRC(sigma,Q2) which each consist of positive coefficients multiplied by mere positive-integer powers of sigma. Without hampering by constraints that sum is clearly minimized over sigma=0..3 at sigma=0.

@JAMET Your code has,

   180 - 180*arctan(alpha)/Pi

instead of,

    180 - 180*alpha/Pi

But the arctan step was already done earlier in your code.

@sand15 I though it might be fun to see how large n could be while obtaining an exact result.

3 4 5 6 7 8 9 Last Page 5 of 560