acer

32333 Reputation

29 Badges

19 years, 325 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@sand15 How tight are cons_1, at different n? Are they always equality?

Please do not spam other old threads on this forum with duplicates of your request.

There are more edits you could do, but here is a start. I've deliberately left the bulk of your procedure as it is, since that's your (evolving) style.

I used an appliable module, with the helper procs, shortened some calls utilizing the uses stuff, adjusted the textplot alignments a bit, and adjusted some rounding evalf stuff, and allowed extra arguments to triangle be passed to the final plots:-display via _rest.

restart;

triangle := module()
local ModuleApply, rad, deg;

# Function to convert degrees to radians
rad := proc(deg) evalf(deg * Pi / 180) end proc;
    
# Function to convert radians to degrees
deg := proc(rad) evalf(rad * 180 / Pi) end proc;

ModuleApply:=proc({a::numeric := 0, b::numeric := 0, c::numeric := 0,
                   AngleA::numeric := 0, AngleB::numeric := 0,
                   AngleC::numeric := 0})
    local A, B, C, T, Tr, DegreeA, DegreeB, DegreeC, TA, TB, TC, Area,
          Centroid, AreaLabel, s, digits;
    uses G=geometry, P=plots;
    digits := Digits;

    # Temporary variables for calculations
    local a_calc, b_calc, c_calc, AngleA_calc, AngleB_calc, AngleC_calc,
          AngleA_rad, AngleB_rad, AngleC_rad;

    a_calc := a;
    b_calc := b;
    c_calc := c;
    AngleA_calc := AngleA;
    AngleB_calc := AngleB;
    AngleC_calc := AngleC;

    # Calculate missing sides or angles
    if a_calc = 0 then
        if AngleA_calc <> 0 and AngleB_calc <> 0 then
            a_calc := b_calc * sin(rad(AngleA_calc)) / sin(rad(AngleB_calc));
        elif AngleA_calc <> 0 and AngleC_calc <> 0 then
            a_calc := c_calc * sin(rad(AngleA_calc)) / sin(rad(AngleC_calc));
        end if;
    elif b_calc = 0 then
        if AngleB_calc <> 0 and AngleA_calc <> 0 then
            b_calc := a_calc * sin(rad(AngleB_calc)) / sin(rad(AngleA_calc));
        elif AngleB_calc <> 0 and AngleC_calc <> 0 then
            b_calc := c_calc * sin(rad(AngleB_calc)) / sin(rad(AngleC_calc));
        end if;
    elif c_calc = 0 then
        if AngleC_calc <> 0 and AngleA_calc <> 0 then
            c_calc := a_calc * sin(rad(AngleC_calc)) / sin(rad(AngleA_calc));
        elif AngleC_calc <> 0 and AngleB_calc <> 0 then
            c_calc := b_calc * sin(rad(AngleC_calc)) / sin(rad(AngleB_calc));
        end if;
    end if;

    if AngleA_calc = 0 then
        AngleA_calc := deg(arccos((b_calc^2 + c_calc^2 - a_calc^2) / (2 * b_calc * c_calc)));
    end if;
    if AngleB_calc = 0 then
        AngleB_calc := deg(arccos((a_calc^2 + c_calc^2 - b_calc^2) / (2 * a_calc * c_calc)));
    end if;
    if AngleC_calc = 0 then
        AngleC_calc := 180 - AngleA_calc - AngleB_calc;
    end if;

    # Convert angles to radians for calculation
    AngleA_rad := rad(AngleA_calc);
    AngleB_rad := rad(AngleB_calc);
    AngleC_rad := rad(AngleC_calc);

    # Define points A, B, and C
    G:-point(A, 0, 0);
    G:-point(B, c_calc, 0);
    G:-point(C, b_calc * cos(AngleA_rad), b_calc * sin(AngleA_rad));

    # Calculate the area using Heron's formula
    s := (a_calc + b_calc + c_calc) / 2;
    Area := sqrt(s * (s - a_calc) * (s - b_calc) * (s - c_calc));
    Area := evalf[4](evalf[digits](Area));

    # Calculate the centroid of the triangle
    Centroid := [(0 + c_calc + b_calc * cos(AngleA_rad)) / 3, (0 + 0 + b_calc * sin(AngleA_rad)) / 3];

    # Text plot for side labels
    T := P:-textplot([[1/2 * c_calc, 0, cat("c = ", evalf[7](evalf[digits](c_calc))), align = below],
                      [1/2 * c_calc + 1/2 * b_calc * cos(AngleA_rad) + 1/30 * a_calc,
                       1/2 * b_calc * sin(AngleA_rad),
                       cat("a = ", evalf[7](evalf[digits](a_calc))), align = [right,above]],
                      [1/2 * b_calc * cos(AngleA_rad) - 1/30 * a_calc,
                       1/2 * b_calc * sin(AngleA_rad), cat("b = ",
                       evalf[7](evalf[digits](b_calc))), align = [left,above]]]);

    # Text plot for angle labels
    TA := P:-textplot([0, 0, cat(evalf[3](evalf[digits](AngleA_calc)), "°"), align = [right,below]]);
    TB := P:-textplot([c_calc, 0, cat(evalf[3](evalf[digits](AngleB_calc)), "°"), align = [left,below]]);
    TC := P:-textplot([b_calc * cos(AngleA_rad), b_calc * sin(AngleA_rad),
                      cat("  ",evalf[3](evalf[digits](AngleC_calc)), "°"), align = [right,above]]);

    # Text plot for the area of the triangle
    AreaLabel := P:-textplot([Centroid[1], Centroid[2], cat("Area= ", Area), align = above]);

    # Display the triangle with labels
    P:-display([G:-draw([G:-triangle(Tr, [A, B, C])],
                        font = [times, roman, 18], labels = [x, y],
                        axes = none, printtext = true), T, TA, TB, TC, AreaLabel],_rest);
end proc;
end module:

triangle(a=1,b=1,c=sqrt(2.), size=[600,500]);

triangle(a=1,b=2,c=sqrt(3.), size=[600,500]);

triangle(a=sqrt(3.),b=1,c=1, size=[800,500]);

 

 


Download SEC_ac1.mw

nb. Never do evalf[4](...) or evalf(...,4) of a complicated formula., even if it exactly/symbolically represents some constant value. However It's OK to use such a call on an already-computed float value, to get final rounding effects. But you don't want to accidentally make the whole float computation be done at low working precision. If you accidentally do it on a formula then it only uses 4 digits of working precision and that will often lead to a rubbish result due to numeric roundoff, loss-of-precision, catastrophic cancellation, etc. Here are two ways to go wrong, and two ways to get it better:

restart;
ee := sin(exp(sqrt(11/10))):
evalf[4](ee); # whoops

.2827

restart;
ee := sin(exp(sqrt(11/10))):
evalf[4](evalf[Digits](ee)); # whoops

.2827

restart;
ee := sin(exp(sqrt(11/10))):
evalf[Digits](ee);
evalf[4](%);  # OK

.2834055537

.2834

restart;
digits:=Digits:
ee := sin(exp(sqrt(11/10))):
evalf[4](evalf[digits](ee));  # OK

.2834

Download dig_ex.mw

@mmcdara You wrote, "the Statistics:-NonlinearFit solver uses Optimization:-NLPSolve" but that is not true.

The Statistics:-NonlinearFit command calls Optimization:-LSSolve.

I've changed the Product field for this posting from "MapleSim" to "MaplePrimes".

One difference between a Reply and an Answer is that all Replies appear above all Answers, regardless of when they are posted. (You didn't query about it; I mention it because I think that it's an important consideration.)

@C_R You wrote, "Does numcpus=1 remove all logical cores from the computation?"

It should use just one logical core. You can't "remove" them "all", since then there'd be no thread to do any computation.

@SUN ZHUOYU Your original had an attempt with insequence.

But that option makes an animation of the sequnce. You can also use your original, but without using that option.

   display(seq(subs(aa = i, eval(f))(p), i = 1 .. 25))

@Andiguys Please do not post a wholly separate new Question thread for this. It would be flagged as a duplicate then deleted. There is no need for additional separate Question threads for this. (If you want to add a proper description/explanation then do so as a Reply in this very Question.)

You can do,

   R3 := sigma*C*Q1 + nu*C*Q2 + 0.6*C*mu*(Q1 + Q2) + piecewise(mu = 0, 0, Vr*k)

Here that is, with cleanup and removal of clutter and unnecessary steps or operators.

N5_ac.mw

When I get a chance I'll look at putting it into a reusable procedure (with parameters x,y instead of having those fixed in DATA) so that generating the table data is terse and tidy. That may or may not happen some evening in the next week.

@Andiguys Earlier you wrote that,

    Q3 = x*d - delta*(Q1 + Q2)

and now in your N5.mw worksheet you no longer have that strict equality, and you're letting Q3 be an independent parameter (with an allowed range supplied earlier by me; admittedly using related formulae at the lower end).

So is that strict equality for Q3 no longer forced alone (ie. except as possible consequence of the other constraints)?

ps. Why are you including your C5 constraint? What do you think that it's enforcing? (I ask because you don't describe the objective, constraints, and formulas for each model you've shown in all these worksheets. That can make it tricky to distinguish between programming mistakes and conceptual mistakes.)

Since I've been working (on and off) on my own expression compactifier for over a year perhaps I might respectfully offer some suggestions:


a) store the actions foremost (and their results secondarily)
b) have it act recursively (and store results as it goes, using a suitable data structure)
c) use an appliable module, and have the best-result-found-so-far be accessible from some module export after you interrupt the search in mid-computation
d) don't try and make it support assumptions in separate internal method choices. Instead, just allow assuming to be used when you call your tool.
e) allow the length-metric to be passed in optionally (LeafCount is not a bad default, but other choices are `simplify/size/size`, or even `length`, or a weighted value using codegen:-cost
f) allow the action-chain to be optionally the return value, or at least part of it
g) have a default time-limit for it (at least for total operation, and preferably for sub-steps). Allow a user-specified time-limit to be an optional argument.
h) allow custom operations (operators/procedures with single input/output) to be passed as an option and so added to the set of possible actions.
i) allow things like evalc to be toggled on/off as an option. (assumes names are real)
j) don't forget acttions like rationalize, expand, normal, etc.
k) don't forget to try collect, which is often very effective (but brings with it even more choices and combinatorial growth.
l) there can be a benefit to splitting temporarily by numer and denom.
m) allow the same action to appear more than once in the action-chain.
n) don't forget that when using convert you can get quite different effects fro
m each of:
      exp, ln, expln, trig, sincos, arctan, arcsin, abs, signum, radical, etc
o) don't forget simplify(...,radical) and combine(radical), but don't waste time with the symbolic option which can make the result wrong
p) even if you're just trying a blanket approach, the growth in cost due to combinatorial coverage of attempts means that even rudimentary checks to tell when a method ought have no effect can be beneficial.  
q) additional stopping criteria (target form of intermediate result, recursion depth limit, time limit) can make it much more practical to use.

That's probably more than enough for a beginning.

@Andiguys Hopefully I'll be able to look later at your latest model in N4.mw.

Fwiw, the earlier revision (N1) with 3D plot is not at a local minimum of its unconstrained surface. That's why I added the constraints in that plot, to visually show that the optimum found was tight up against some constraints.

@nm I'd agree with you that odetest ought to use limit here.

(...and, better to have a duplicate report than none)

@KIRAN SAJJAN I asked how you wanted it laid out, with Gr taking multiple values. You have not answered that.

For example, you could have all the Cf columns together, and all the Nux columns together. Or you could have Cf,Nux in pairs, for each Gr.

@Andiguys 

You don't need the DirectSearch package to get the result I obtained in my previous Reply above. (I already gave you two separate URLs for obtaining it, btw). My use of that package merely confirmed -- even without substituting nu=sigma, etc -- the result I had already obtained without it, in the same worksheet: numerically using Minimize which my worksheet showed, and also symbolically which I didn't show.

Your previous attachment N1.mw contained plot3d call of something that doesn't contain I1 and I2, and the ranges you passed it were for I1 and I2. That doesn't make sense here.

If you have some formula for Q3 -- based on some other fixed parameter values and formulas for Q1,Q2 then why did you attempt to minimize TRC(sigma,nu,Q3) without using any such substitution for Q3?

If I take your formulas present elsewhere in the worksheet for Q1(sigma) and Q2(sigma), and the fixed parameter values present somewhere else in your worksheet, and then use those for a value for Q3, then Minimize succeeds with Digits:=30. In fact the results agree with what I had obtained in my previous worksheet, with Q3 allowed to vary (in a range I deduced from the constraints, with the lower bound the value I actually suspected).

The following attachment makes the various corrections (substituting appropriately for Q3, correcting variables in the plot3d call, use higher Digits): N1_11_acc.mw

Here is the 3D plot, including the TRC surface as well as transparent vertical surfaces for the 2D constraints.



ps. I believe that this would have been simpler if you had provided description of your methodology earlier.

@KIRAN SAJJAN You description is missing necessary important details.

You write that you want eta to go from 0 to 20 (in 1000 steps). You write that you want the results in table, and tried to use a Matrix.

Are you trying to create a Matrix that includes all four Gr values? What's the xi value(s)? How would that be laid out as columns in a Matrix, if either xi or Gr are to have multiple values?

First 35 36 37 38 39 40 41 Last Page 37 of 592