acer

30772 Reputation

29 Badges

19 years, 9 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@Paras31 It's confusing if your worksheet assign any numeric value to that name.

Your equations appear to contain the name,

   `#mover(mi("δ",fontstyle = "normal"),mo("ˆ"))`

(which pretty-prints like delta with a circumflex accent above it).

But that doesn't seem to be assigned any numeric value. Have I missed that assignment? If not, then what is its value?

@AHSAN You can add any column you want.

What's your explicit definition of the "residual" here? Use that.

@jrive I am going to submit a (likely duplicate) bug report on the following weakness, which characterizes an underlying weakness in simplify.

restart;

Len := expr -> [MmaTranslator:-Mma:-LeafCount(expr),
                length(expr),
                `simplify/size/size`(expr)]:

 

W := (K*(R + Q) + S)/K;

(K*(R+Q)+S)/K

simplify(W);
Len(%);

(K*(R+Q)+S)/K

[11, 33, 27]

simplify(W,size);
Len(%);

(K*(R+Q)+S)/K

[11, 33, 27]

expand(W);
Len(%);

Q+R+S/K

[8, 21, 21]

Download simp_weakness.mw

@jrive If F (the denominator, say) is obtained as the common multiplicative term that one wants to distribute through the sum (numerator), then I've showed that either of the following attain your target,

   map(`/`, Zin*F, F)
or,
   expand(Zin, F, op(Zin*F))


I picked off F as the whole term in the denominator. And of course that involved no up front check that it were indeed a "common" (multiplicative) factor that could be usefully cancelled via distribution through the numerator sum.

ps. The reason that I originally went with collect is that it sometimes happens that a judicious collect call gets a more compact result than does simplify(...,size). I have a hard-working compactifier oracle that looks for such, by trying different variable choices and followup coefficient-action (3nd arg).

The form of your target expression (and my interest in finding a shorter/shortest form) made me think trying collect first. In contrast, the form of your input expression leads more to using a distributed multiplication or a controlled expansion -- but one has to "see" that it'd work.

A variation using a controlled expand.

The subterms not to expand are determined according to sign of power (ie, in denominator or numerator).

The use of op here does not contain an ad hoc positional determiner. It simply gets all summands of the numerator.

restart;

Zin := ((Rsp + (omega*L2 - omega02^2*L2/omega)*I)
       *(Rpp + (omega*L1 - omega01^2*L1/omega)*I) + 0.01*omega^2*L1*L2)
       /(Rsp + (omega*L2 - omega02^2*L2/omega)*I):

 

F := 1/select(type,Zin,anything^(negint)):

expand(Zin, F, op(Zin*F));

Rpp+I*(omega*L1-omega01^2*L1/omega)+0.1e-1*omega^2*L1*L2/(Rsp+I*(omega*L2-omega02^2*L2/omega))


Download expand_ex.mw


More general use would also involve checking the form, ie. a type-check as to whether the numerator were indeed a sum, etc.

@C_R In my earlier Reply I already had a more programmatic variation of,

   F := 1/op(2,Zin):
   map(`/`,Zin*F,F);

That might be shortened further to,

  F:= op(2,Zin):
  map(`*`,Zin/F,F);

where the main difference was that earlier I programmatically extracted F the (unexpanded) denominator whereas your approach merely picks both it and the remaining numerator off as an operands whose ordinals are determined by eye.

Using such manual determination of the denominator is not of general use. Also, there could be a numeric coefficient, or multiple factors in the denominator, etc, in which case the op determiners (1st argument) would need to be different.

See also my followup Reply about using a controlled/restricted expand instead of a mapped multiplication.

@janhardo I put it back in as the original float, to avoid confusion.

With our hands on the denominator (unexpanded, and also the "common" term), then we could handle this particular example like so.

Zin := ((Rsp + (omega*L2 - omega02^2*L2/omega)*I)
       *(Rpp + (omega*L1 - omega01^2*L1/omega)*I) + 0.01*omega^2*L1*L2)
       /(Rsp + (omega*L2 - omega02^2*L2/omega)*I);

((Rsp+I*(omega*L2-omega02^2*L2/omega))*(Rpp+I*(omega*L1-omega01^2*L1/omega))+0.1e-1*omega^2*L1*L2)/(Rsp+I*(omega*L2-omega02^2*L2/omega))

That denominator, untouched and not expanded...

FF := 1/select(type,Zin,anything^(negint));

Rsp+I*(omega*L2-omega02^2*L2/omega)

map(`/`,Zin*FF,FF);

Rpp+I*(omega*L1-omega01^2*L1/omega)+0.1e-1*omega^2*L1*L2/(Rsp+I*(omega*L2-omega02^2*L2/omega))

Download collect_ex6.mw

I ought to point out that this does not systematically check for the particular form that allows this to work. Without such a systematic process I label this as ad hoc.

Since the cited target result is not the simplest form possible then defining such a systematic process ought to be preceded by a clear definition of the candidate form. (I think I see one.)

On the other hand, the choice of variables that were used earlier is also an ad hoc aspect.

@nm 

Yes, Mma's simplification is ok. But the following is even simpler.

Rpp+(I*(omega-omega01^2/omega)+0.1e-1*omega^2*L2/(Rsp+I*(omega-omega02^2/omega)*L2))*L1


I can get that with a minor variant. (I didn't before; it was not the OP's target.)


ps. quibble: I notice that you changed the 0.01 to 100, in your Mma example.

@jrive I'm sorry that my effort is so looked-down upon.

Personally, I find the following to be slightly complicated but not advanced.

FF := 1/select(type,Zin,anything^(-1)):
simplify(Zin,{FF=freeze(FF)}):
thaw(collect(%,[Rpp,L2],simplify));

1.000000000*Rpp+0.1e-1*omega^2*L1*L2/(Rsp+I*(omega*L2-omega02^2*L2/omega))+I*L1*(omega^2-1.*omega01^2)/omega

or,

FF:=1/select(type,Zin,anything^(-1)):
simplify(Zin,{FF=FFF}):
subs(II=I,FFF=FF,collect(subs(I=II,%),[Rpp,II,omega]));

1.000000000*Rpp+I*(1.000000000*omega*L1-1.000000000*omega01^2*L1/omega)+0.1000000000e-1*omega^2*L1*L2/(Rsp+I*(omega*L2-omega02^2*L2/omega))

I made an effort to not have those irritating float artefacts.

I also made an effort to explain the extra steps I took to work around issues (eg. collecting wrt I, the float contagion, etc).

On the bright side at least it isn't one of those very poor and ad hoc solutions involving op and by-hand/eye picking of operand numbers/positions. That's a nearly useless approach!

You tagged this with simplify. But if you're attempting some notion of simplification then why does your target form not have the L1 (or L2) factored out of some subexpressions, eg,
   omega*L1 - omega01^2*L1/omega
instead of,
    L1*(omega - omega01^2/omega)
?

I'm just curious. The target can be attained using collect as the main tool. But I want to be sure that I am using the right target.

Also, it looks as if the Rac term was just some typo.

@C_R The particular error message shown by the OP is not the primary issue. The outer integration won't succeed as intended without proper syntax, which it lacked by having an fdiff call as first argument and a bare range as second argument. In M2024.1 one might get back, say, an unevaluated int call, say, but such a result is not meaningful or useful.

Numeric integration is wanted in this case, as part of this described exercise. And one can enable that here by one of these 1) using the numeric option to lowercase int, 2) making the upper bounds passed to int be numeric floats, or 3) invoking evalf(Int(...)) instead. So that's one aspect.

Another aspect is to also repair the syntax for the arguments passed, and fixing that is required if a float result is wanted. That can be achieved for all three of the above approaches, by using an operator for the first argument so that the x value used in each fdiff call is an actual numeric value, as I mentioned in my Answer. That happens to succeed (slowly), even with stock options, for this given example and time-value t=0.

Ie, using,
   x->fdiff(sol(x, t), [t = 0]), a .. b
as first arguments for all three,

kernelopts(version);

`Maple 2024.1, X86 64 LINUX, Jun 25 2024, Build ID 1835466`

Using option numeric to the int call.
restart;
with(PDEtools): with(plots): with(DEtools):
pde := diff(v(x, t), t, t) = diff(v(x, t), x, x):
f := xi -> exp(-xi^2):
a := -10: b := 10: dx := 1/50: t_final := 10:
pds := pdsolve(pde, {v(a, t) = 0, v(b, t) = 0,
               v(x, 0) = f(x + 5), D[2](v)(x, 0) = -eval(diff(f(x), x), x = x + 5)},
               numeric, range = a .. b, time = t, spacestep = dx):
sol_proc := rhs(pds:-value(output = listprocedure)[3]):
sol := (x, t) -> piecewise(a < x and x < b, sol_proc(x, t), 0):
int(x->fdiff(sol(x, t), [t = 0]), a .. b, numeric);

0.2324739513e-10

Using float values in the range in the int call.
restart;
with(PDEtools): with(plots): with(DEtools):
pde := diff(v(x, t), t, t) = diff(v(x, t), x, x):
f := xi -> exp(-xi^2):
a := -10.0: b := 10.0: dx := 1/50: t_final := 10:
pds := pdsolve(pde, {v(a, t) = 0, v(b, t) = 0,
               v(x, 0) = f(x + 5), D[2](v)(x, 0) = -eval(diff(f(x), x), x = x + 5)},
               numeric, range = a .. b, time = t, spacestep = dx):
sol_proc := rhs(pds:-value(output = listprocedure)[3]):
sol := (x, t) -> piecewise(a < x and x < b, sol_proc(x, t), 0):
int(x->fdiff(sol(x, t), [t = 0]), a .. b);

0.2324739513e-10

Using evalf(Int(...)) instead of int(...).
restart;
with(PDEtools): with(plots): with(DEtools):
pde := diff(v(x, t), t, t) = diff(v(x, t), x, x):
f := xi -> exp(-xi^2):
a := -10: b := 10: dx := 1/50: t_final := 10:
pds := pdsolve(pde, {v(a, t) = 0, v(b, t) = 0,
               v(x, 0) = f(x + 5), D[2](v)(x, 0) = -eval(diff(f(x), x), x = x + 5)},
               numeric, range = a .. b, time = t, spacestep = dx):
sol_proc := rhs(pds:-value(output = listprocedure)[3]):
sol := (x, t) -> piecewise(a < x and x < b, sol_proc(x, t), 0):
evalf(Int(x->fdiff(sol(x, t), [t = 0]), a .. b));

0.2324739513e-10


Download pde_num_e2.mw

@mmcdara Thanks, that's the kind of thing I'd surmised. But the numeric requirements are imprecise.

My concern is that such a process is not a test of only the numeric pde solver. Its results rely upon not only behavior of the three different & separate numeric solvers I mentioned but also upon their interplay.

Failure to attain some (as yet unstated) degree of numeric accuracy cannot therefore be a proper gauge of numeric performance of any of sole component part of that process. Eg. failure might say nothing about the numeric pde solver alone.

I supposed that accuracy of the integration step would need be coarser than that of the diffentiation step, that in turn being coarser than that of the pde scheme. But the particulars of that might need be problem specific. And attaining an upfront, explicit, accuracy goal might need per-problem tuning at any/all of those levels.

@GFY By the way, it is also possible to do it with fsolve (as a modification/correction of the earlier attempt). Here, I augment with undefined, for the absent root values.

You can also scale any you choose, eg. by 3.

I use option remember to avoid calling fsolve multiple times for the same input (ie. same omega__v, or r, value).

You could make this more sophisticated.

restart;

plots:-setoptions(size=[500,200]);

det_num := -0.9633005975*Omega^6 + (0.9630831768*omega__v^2 + 0.9337694145)*Omega^4 + (-0.9338923707*omega__v^2 - 0.01494064902)*Omega^2 + 0.01494064902*omega__v^2 = 0;

-.9633005975*Omega^6+(.9630831768*omega__v^2+.9337694145)*Omega^4+(-.9338923707*omega__v^2-0.1494064902e-1)*Omega^2+0.1494064902e-1*omega__v^2 = 0

ll := proc(varr)
  local i, res; option remember;
  res := [fsolve(eval(det_num, omega__v=varr), Omega=0..infinity)];
  return [res[], seq(undefined, i=1..3-nops(res))];
end proc:

ll(0.8);

[.1275587179, .8003574462, .9758873053]

plots:-display(
  plot(x->ll(x)[1],0..2),
  plot(x->ll(x)[2],0..2),
  plot(x->ll(x)[3],0..2));

det_num := 0.7801238870*Omega^4 + (-9.794000000/r - 1340.585417)*Omega^2 + 13129.69357/r = 0

.7801238870*Omega^4+(-9.794000000/r-1340.585417)*Omega^2+13129.69357/r = 0

ll2 := proc(varr)
  local i, res; option remember;
  res := [fsolve(eval(det_num, r=varr), Omega=0..infinity)];
  return [res[], seq(undefined, i=1..2-nops(res))];
end proc:

plots:-display(
  plot(x->ll2(x)[2],0.01 .. 0.1),
  plot(x->3*ll2(x)[1],0.01 .. 0.1));

 

Download fuxian_ac2.mw

1 2 3 4 5 6 7 Last Page 2 of 564