## 30685 Reputation

18 years, 355 days

## spacecurve...

Here I use the formula as in your picture, with the x- and y-components switched. And so a similar plot can attain.

plots:-display(
plots:-spacecurve([t*cos(t),t*sin(t),2*sqrt(2)/3*t^(3/2)],t=0..Pi,
thickness=4,color=black),
axes=normal,view=[-3..3,-2..4,-2..8], scaling=constrained,
orientation=[50,70,0]);


You also mentioned 2D plotting, but that could mean several different things and you haven't explained what you are after. Perhaps a projection of that spacecurve, onto the x-y or some other plane?

## one way...

 > G := x^5 - 5*x^4 - 35*x^3:
 > C := mul(x-(a+i*d),i=0..4):
 > S := solve({seq(coeff(C,x,i)=coeff(G,x,i),i=3..4)});

 > R := seq(eval(a+i*d,S[1]),i=0..4);

 > P := expand(eval(C,S[1]));

The roots are R, and the polynomial is P.

## different float expressions...

@C_R Notice that your code does not assign the expression to a name, and merely reuse it at the different values of Digits.

Rather, your code explicitly re-forms the expression at the different values of Digits.

The 1e-11 invocation forms the very same float expression at both Digits settings. But the 0.1*10^11 forms different float expressions at those two different values of Digits.

The differing coefficients makes the expressions being passed be to is be different (ie. different address, etc).

That makes the remember table get used for one flavor (where the expression passed is identical) but not the other (where the expression passed is different).

 > Digits := 10;

FLOAT(3): .1e-10
INTPOS(2): 1
INTNEG(2): -11

FLOAT(3): .1000000000e11
INTPOS(2): 1000000000
INTPOS(2): 1

 > Digits:=30;

FLOAT(3): .1e-10
INTPOS(2): 1
INTNEG(2): -11

FLOAT(3): 10000000000.0
INTPOS(2): 100000000000
INTNEG(2): -1

On the other hand, if you formed the two expressions just once, up front, then the remembered can interfere (here, consistently).

eval_of_range_in_ln_ac2.mw

So, the cause is that (only) one of those constructions produce identical results at differing Digits.

## recovery...

Your attachment had an invalid Equation blob of XML, just after the "Kronecker Delta" text.

Removing that I get the following, which opens ok in Maple 2022.2.

Lecture_2_notes_ac.mw

ps. Maple 2024 seems to have much less of this kind of problem (and might even be able to itself recover your attachment acceptably...). If your school offers it then I suggest you upgrade.

ps. The Mapleprimes posting editor's toolbar has a green up-arrow that allows on to upload and attach worksheet documents to posts. In future you could use that instead of a 3rd-party download site.

## example...

Your code snippet shows the name shift being used both as an optional parameter of F as well as for an equation in each of the lists passed for the Q, vec, and point parameter of F. It seems that you want to be able to pass those independently, when calling F.

You might also want one of those to override the other, ie. either the instances inside the lists, or the separate parameter. I've made a guess as to which that might be, since you haven't really explained your goal. (You should easily be able to switch which might be an override, or instead utilize them wholly separately, and/or assign the values to three different locals, etc.)

Using variants on the code below you should be able to access the shift equations (and their rhs values) specified by each of your Q, vec, or point lists. Accessing each of those simply involves using the eval command.

Eg., inside F, you can do any of,
eval(':-shift',Q)
eval(':-shift',vec)
eval(':-shift',point)

One of your queries here is about how to access the rhs of shift=something when that appears in a list. That was also in a Reply of another recent Question of yours on this site. And I used the same approach above as previously recommended -- 2-argument eval -- the only difference is that now you have different local/param vs global references of the name hanging about.

(Again, you didn't state whether you wanted the separate shift optional parameter of F be subordinate, or an override, or unrelated to those three. I've made a guess, and demonstrated a way in which they could inter-relate. Remove that aspect, if not desired.)

 > restart; F := proc(point::list:=[':-symbolsize'=12,':-symbol'=':-solidcircle',                         ':-colour'=':-blue',':-shift'=0.4],           shift::float:=0.7)   local lshift;   if eval(':-shift',point)::float then     lshift := eval(':-shift',point);   else     lshift := shift;   end if;   lshift; end proc:

 > F();

 > F([symbolsize=12,symbol=solidcircle,colour=blue]);

 > F([symbolsize=12,symbol=solidcircle,colour=blue,':-shift'=foo]);

 > F([symbolsize=12,symbol=solidcircle,colour=blue,':-shift'=':-shift']);

 > F([symbolsize=12,symbol=solidcircle,colour=blue,':-shift'=0.3]);

I think that you could make it more clear and explicit what behavior you want an expect here. Showing a representative variety of function calls and corresponding expected results (even if the proc code is not given) is a basic thing. You should be explicit about the functionality you want.

ps. I suggest that you run maplemint on your procedures. I expect that you might find that it reports quite a few cases where global names are being used without protection against having prior values. (Eg. Try to run your example with :-shift assigned a float value at the top-level, and see what breaks, etc, etc.) I've tried to make the above "mint-clean".

pps. I understand that your actual procedures might be too long to include here. But you really ought to at least try to write a shorter proc and example that is self-contained and illustrates your query and runs stand-alone. In this case it wouldn't take long.

## black box...

You wrote that you wanted to solve the pde numerically, so I'll address that methodology.

In that case you could try setting up that BC with a call to a black-box procedure, by which I mean a procedure that returns the numeric integration result when passed a numeric input, but for which a symbolic function call returns unevaluated.

This technique can also be used for some other flavors of example; ie. the black-box procedure doesn't necessarily involve an integral.

 > restart;
 > pde := diff(v(x, t), t) = diff(v(x, t), x, x);

 > f := x -> exp(-x^2);

 > a := -1.68858; b := 1.68858; delx := 1e-2;

 > K := proc(x) #option trace;  local res, s;  if not x::numeric then return 'procname'(args); end if;  res := evalf[15](1 - Int(f(f(s)), s = 0 .. x, method=_d01ajc, digits=15, epsilon=1e-10));  evalf[10](res); end proc:
 > K(x); # unevaluated. like a black box.

 > plot(K(x), x=-2..2);

 > sol := pdsolve(pde, {v(a, t) = 0, v(b, t) = 0,                      v(x, 0) = K(x)},                numeric, range = a .. b, time = t, spacestep = delx):
 > F[1] := sol:-value(t=1,output=listprocedure):
 > plot(eval(v(x,t),F[1]), a..b);

 > sol:-plot3d(t=0..5,x=a..b,axes=boxed);

 > sol:-animate(t=1,frames=100);

That region can be shaded using the plots:-shadebetween command. (There are several other ways, using say plots:-inequal or plots:-implicitplot)

Just for fun, I played with some other options for the overall look&feel. Adust to taste.

shb.mw

## maybe this...

See here the response about disabling scrollable rtables.

Disabling that GUI preference seems to have fixed a similar instance of the problem.

## example...

Is this the kind of effect that you're after?

(There might be a terser way; I just edited what you had before...)

 > restart;
 > F := proc(ee, LL)   local Hx,Hy;   Hx := nprintf(#mfenced(mrow(%a,mo("⁢"),mi("x")));,                 Typesetting:-Typeset(Typesetting:-EV(LL[1])));   Hy := nprintf(#mfenced(mrow(%a,mo("⁢"),mi("y")));,                 Typesetting:-Typeset(Typesetting:-EV(LL[2])));  Typesetting:-mrow(InertForm:-Typeset(InertForm:-Display(eval(eval(InertForm:-MakeInert(factor(ee)), [%* = *]) = InertForm:-MakeInert(sort(algsubs(b*y = Hy, algsubs(a*x = Hx, ee)), order = plex(Hx,Hy))), =~([a, b], LL)), inert = false)), Typesetting:-mo("="), InertForm:-Typeset(eval(ee, =~([a, b], LL)))); end proc:
 > p := a^3*x^3 + 3*a^2*b*x^2*y + 3*a*b^2*x*y^2 + b^3*y^3;

 > L := [[2, 3], [1, 2], [1/3, -sqrt(2)]];

 > ans := F~(p, L);

 > print~(ans):

## example...

I have used Maple 2024.1 below.

You can use fprintf instead of printf, if you want to write to a file.

 > restart:
 > F := proc(ee,LL)   uses InertForm, Typesetting;   mrow(Typeset(Display(eval(eval(MakeInert(factor(ee)),[%*=*])                                  =MakeInert(subs(b=MakeInert(b*y)/y,                         a=MakeInert(a*x)/x,p)),[a,b]=~LL),                        inert=false)),        mo("="),Typeset(eval(ee,[a,b]=~LL))) end proc: p := (a*x)^2 - 2*a*x*b*y + (b*y)^2: L := [[sqrt(2),3],[2,5],[3,12],[1/3,5/7]]: ans := F~(p, L):

 > print~(ans):

 > RR := cat( "\n\\documentclass[12pt,a4paper]{article} \\usepackage[left=2cm, right=2cm, top=2cm, bottom=2cm]{geometry} \\usepackage{amsmath} \\usepackage{amsthm} \\usepackage{enumitem} \\theoremstyle{definition} \\newtheorem{ex}{Exercise} \\begin{document}\n\n", seq(sprintf("\\begin{ex}\n\$%s \$\n\\end{ex}\n",             latex(ee, output=string)),ee=ans), "\n\\end{document}"):

 > printf(RR);

\documentclass[12pt,a4paper]{article}
\usepackage[left=2cm, right=2cm, top=2cm, bottom=2cm]{geometry}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{enumitem}
\theoremstyle{definition}
\newtheorem{ex}{Exercise}
\begin{document}

\begin{ex}
$\left(\sqrt{2}\, x -3 y \right)^{2}=\left(\sqrt{2}\cdot x \right)^{2}-2\cdot \left(\sqrt{2}\cdot x \right)\cdot \left(3\cdot y \right)+\left(3\cdot y \right)^{2}=2 x^{2}-6 \sqrt{2}\, x y +9 y^{2}$
\end{ex}
\begin{ex}
$\left(2 x -5 y \right)^{2}=\left(2\cdot x \right)^{2}-2\cdot \left(2\cdot x \right)\cdot \left(5\cdot y \right)+\left(5\cdot y \right)^{2}=4 x^{2}-20 x y +25 y^{2}$
\end{ex}
\begin{ex}
$\left(3 x -12 y \right)^{2}=\left(3\cdot x \right)^{2}-2\cdot \left(3\cdot x \right)\cdot \left(12\cdot y \right)+\left(12\cdot y \right)^{2}=9 x^{2}-72 x y +144 y^{2}$
\end{ex}
\begin{ex}
$\left(\frac{x}{3}-\frac{5 y}{7}\right)^{2}=\left(\frac{1}{3}\cdot x \right)^{2}-2\cdot \left(\frac{1}{3}\cdot x \right)\cdot \left(\frac{5}{7}\cdot y \right)+\left(\frac{5}{7}\cdot y \right)^{2}=\frac{1}{9} x^{2}-\frac{10}{21} x y +\frac{25}{49} y^{2}$
\end{ex}

\end{document}

## scrollable rtable display...

Does this behavior get affected/improved if you change the interface(rtablesize) setting?

Does this behaviour get affected/improved if you manage to disable the (new in M2024) so-called scrollable rtable/Matrix/Vector display?

ps. I have changed your Post into a Question.

See the Comparing sum and add section on the ?sum,details Help page.

And also note that the add command has special evaluation rules on its first parameter.

Also, your myfac procedure can be done using mul (or add of the powers), instead of a loop. A symbolic formula for it can also be constructed using the product (or sum) commands.

Here is an explanation of how it was going wrong for you (note the error message's meaning), as well as alternatives mentioned.

 >
 >
 >

 >

 >

 >

Error, invalid input: myfac expects its 1st argument, n, to be of type nonnegint, but received i

 >

Error, invalid input: myfac expects its 1st argument, n, to be of type nonnegint, but received i

 >

 >

 >

 > Alternate way to write myfac. nb. Another is to use 3*2^add(i,i=0..n)
 >

 > Symbolic formula for myfac, using product instead of mul

 >

 >

 > Note also,

## sqrt...

Is this more what you're after? (Using Maple 2021.2)

I notice that your 2D Input is actually entered using the sqrt command. So one alternative (to fixing it up after the fact) might be to instead enter those with (...)^(1/2) instead of sqrt(...).

 \left\{w = \frac{a_{3} \left(9 \lambda  a_{4} a_{5}-2 a_{3}^{2}\right)}{54 a_{4}^{2}} , a_{1} = 0, a_{2} = -\frac{3 \lambda  a_{4} a_{5}-2 a_{3}^{2}}{6 a_{4}}, \alpha_{0} = -\frac{a_{3}}{3 a_{4}}, \alpha_{1} = \mp \sqrt{-\frac{a_{5}}{2 a_{4}}} , \beta_{0} = \mp \sqrt{-\frac{\lambda^{2} B_{1}^{2} a_{5}-\lambda^{2} B_{2}^{2} a_{5}-\mu^{2} a_{5}}{2 \lambda  a_{4}}} \right\} \left\{w = \frac{a_{3} \left(9 \lambda  a_{4} a_{5}-2 a_{3}^{2}\right)}{54 a_{4}^{2}} , a_{1} = 0, a_{2} = -\frac{3 \lambda  a_{4} a_{5}-2 a_{3}^{2}}{6 a_{4}}, \alpha_{0} = -\frac{a_{3}}{3 a_{4}}, \alpha_{1} = \mp \sqrt{-\frac{a_{5}}{2 a_{4}}} , \beta_{0} = \mp \sqrt{-\frac{\lambda^{2} B_{1}^{2} a_{5}-\lambda^{2} B_{2}^{2} a_{5}-\mu^{2} a_{5}}{2 \lambda  a_{4}}} \right\}

## floats, num_steps, Tabulate...

I don't see num_steps defined or assigned. Perhaps you intend that as, say, ceil((tmax - 0)/dt) or similar.

You don't ever evalf the contents of U0, so everything blows up as enormous symbolic expressions. That's the basic reason why it appeared to take forever. I expect that you intended to utilize floating-point values.

You can use Tabulate to overwrite (in-place) an output of the running plotU. If you want all the intermediate plots shown then you could use print(plotU) instead of your original display(plotU). But note that your original display(plotU) wasn't being assigned to anything. If instead you were to assign all the individual plotU plots as entries in a table TT then after the loop you could display(entries(TT),insequence) and get an animation.

Numerical_Simulation_of_discrete_Klein-Gordon_Equation_ac.mw

ps. I have not revised or examined the underlying algorithm or its implementation. Commenting the code better might be useful.

## ifactors...

It is more generally straightforward to programmatically access the results from the ifactors command, rather than from the ifactor command.

 > x := ifactors(6);

 > x[2];

 > x[2,1,1]

 > x[2,2,1]

One aspect that makes it more sensible is that the methodology can be consistent whether the factors have multiplicity 1 or greater than 1. Eg, whether the original is say 6, or 72. But with ifactor the deconstruction would need a separate case for whether the power was 1 (in which case not actually present) or greater than 1.

 1 2 3 4 5 6 7 Last Page 1 of 319
﻿