janhardo

700 Reputation

12 Badges

11 years, 47 days

MaplePrimes Activity


These are replies submitted by janhardo

@acer 
Thanks for the comprehensive list of pointers.
After reading through the directions list, I still don't understand much of it
a?,b?,c?,d?,e,f?,g,h?,i,j,k,l,m,n,o,p,q
c: is the use of a module in which procedures can be called? 
Where(with ) to start: how is the setup ?

You can also have an expression and run an iteration of simplification commands on it.
That's a different approach than running down a list of simplification commands.

New method discovered: combined two methods

Expressions can be simplified with various combinations of commands.
It is also informative that an expression comes in different forms

Try some expressions your self ...

veeenvoudingings_proc-full_simplify5_Maple_primes.mw

@Carl Love 

Explain again what exactly is meant by your text :

"Your problem comes from using the default equality operator = to check the mathematical equality of algebraic expressions, but = only checks whether the expressions are syntactically identical in their unsimplified form. That's a much stronger form of equality than mathematical equality."

post : 

Use `is` for mathematical equality

Now doing alone simplication examples ...
vereenvoudigings_proc-versie_2_naaar_MPFORUM_DEF.mw

If you see this kind of generic solution, then in my opinion, Maple doesn't know either.
Checking then yields nothing. 

@mmcdara 
Thanks, I try this for expression T, it gives s8 : for  a := full_simplify(T); and with : print~(full_simplify~(T)) s7,s9 and s16 

a := full_simplify(T[2]):
b := convert(rhs~(a), set):
t := map(u -> lhs~(a[[ListTools:-SearchAll(u, rhs~(a))]]) = u, b):
print~(t):

Error, (in anonymous procedure) invalid input: lhs received (s8 = [(-12*cos(3*t)^2-228*cos(3*t)-54)/(-1169+72*cos(3*t)^3-124*cos(3*t)+388*cos(3*t)^2), 1/2*2^(1/2), 1/9*(ln(1+2^(1/2))+2^(1/2))^2, 1/2*exp(1/2*x)*(cosh(1/2*x)-cosh(3/2*x)+sinh(1/2*x)+sinh(3/2*x))])[[1]], which is not valid for its 1st argument, expr

"As several simplification methods lead to the same result, you could be interested in knowing those that give the same."
In other simplifications has this multiple same simplification some uses ?
Interesting question too is, find a simplification what simplified a expression the most .: the procdure must use this one.

@mmcdara 
Thanks, that's a great idea to add a numbering to the simplification commands.
 

I add two simpifications more for trigoniometry and exp 
simplify(combine(expand(simplify(expr)), trig), trig),# special for trigonimetry 
 convert(simplify(combine(simplify(convert(e, trig)))), exp) assuming real # special for exp(x) powers

later i will add some more simplifications for other expressions.
Try to get this simplification
[exp(-1)*exp(x)/sqrt(2 - exp(-2)*exp(x)^2), sqrt(2)/2, (ln(1 + sqrt(2)) + sqrt(2))^2/9, exp(x)/2 - exp(-x)/2]

Rotation cone around the x-axis as start

"maple.ini in users"

(1)

plotCones := proc(degrees_list, view_range)
    local R, param_cone, apply_rotation, kegel, phi, plots_list, degree, colors, i,color;
    uses plots, plottools;

    # Define a list of colors to be used
    colors := ["red", "green", "blue", "cyan", "magenta", "yellow", "orange", "purple", "pink", "brown", "grey"];

    # Define the parametric equation of the cone, shifting it so the top is at (0, 0, 0)
    param_cone := (t, theta) -> [evalf(-t), evalf(t*cos(theta)), evalf(t*sin(theta))];

    # Define a function to apply the rotation matrix to a vector
    apply_rotation := (R, v) -> [
        evalf(R[1,1]*v[1] + R[1,2]*v[2] + R[1,3]*v[3]),
        evalf(R[2,1]*v[1] + R[2,2]*v[2] + R[2,3]*v[3]),
        evalf(R[3,1]*v[1] + R[3,2]*v[2] + R[3,3]*v[3])
    ];

    plots_list := [];

    for i from 1 to nops(degrees_list) do
        degree := degrees_list[i];
        # Assign a color from the list, cycling through if more cones than colors
        color := colors[(i - 1) mod nops(colors) + 1];

        # Convert degrees to radians
        phi := evalf(degree * Pi / 180);

        # Define the rotation matrix around the y-axis
        R := Matrix([
            [evalf(cos(phi)), 0, evalf(sin(phi))],
            [0, 1, 0],
            [evalf(-sin(phi)), 0, evalf(cos(phi))]
        ]);

        # Create a matrix for the cone
        kegel := (t, theta) -> apply_rotation(R, param_cone(t, theta));

        # Add the plot of the current cone to the plots list
        plots_list := [op(plots_list), plot3d(
            kegel(t, theta),
            t = 0 .. 2,
            theta = 0 .. 2*Pi,
            colour = color,
            axes = boxed,
            scaling = constrained,  # Keep the scaling of the axes consistent
            labels = ["x", "y", "z"],
            title = cat("Cone (phi = ", degree, " degrees)"),
            view = view_range
        )];
    end do;

    # Display all the cones in one plot
    display(plots_list, title = "Multiple Rotated Cones with Automatic Colors");
end proc:

# Call the procedure with a list of angles in degrees and view range
plotCones([0, 45, 90, 135, 180, 225, 270, 315], [-3..3, -3..3, -3..3]);

 
 

 

Download _8_kegels_met_random_kleur_maple_primes.mw

Thanks, in the meantime had also done something with tickmarks: 
 tickmarks = [[-2, -1, 0, 1, 2], [-2, -1, 0, 1, 2], [-2, -1, 0, 1, 2]],
The procedure also works with this, only it is static 

Going to modify it with view as well., that's easier for comparing the cones if they are equal.
Looks like the procedure now works well with a cone at an angle to the positive x-axis of 10 degrees and 45 degrees

How to debug this ? 

with(plots):
with(plottools):

plotCone := proc(phi_degrees, x_range::range, y_range::range, z_range::range)
    local R, param_cone, apply_rotation, kegel, phi;

    # Convert degrees to radians
    phi := phi_degrees * Pi / 180;

    # Define the rotation matrix
    R := Matrix([
        [1, 0, 0],
        [0, cos(phi), -sin(phi)],
        [0, sin(phi), cos(phi)]
    ]);

    # Define the parametric equation of the cone
    param_cone := (t, theta) -> [t, t*cos(theta), t*sin(theta)];

    # Define a function to apply the rotation matrix to a vector
    apply_rotation := (R, v) -> [
        R[1,1]*v[1] + R[1,2]*v[2] + R[1,3]*v[3],
        R[2,1]*v[1] + R[2,2]*v[2] + R[2,3]*v[3],
        R[3,1]*v[1] + R[3,2]*v[2] + R[3,3]*v[3]
    ];

    # Create a matrix for the cone
    kegel := (t, theta) -> apply_rotation(R, param_cone(t, theta));

    # Plot the cone with specified ranges for the axes
    plot3d(
        kegel(t, theta),
        t = 0 .. 2,
        theta = 0 .. 2*Pi,
        x = x_range,
        y = y_range,
        z = z_range,
        axes = boxed,
        scaling = constrained,  # Keep the scaling of the axes consistent
        labels = ["x", "y", "z"],
        title = cat("Cone around the positive x-axis (phi = ", phi_degrees, " degrees)")
    );
end proc:

# Call the procedure with a desired angle in degrees and specified ranges for x, y, and z axes
plotCone(10, -2 .. 2, -2 .. 2, -2 .. 2);  # Adjust the ranges as needed

Error, (in plot3d) unexpected options: [x = -2 .. 2, y = -2 .. 2, z = -2 .. 2]

Thanks, I did not know this plot command. 
There is also a 3d version of it, but let's see how to use it.
The idea of the procedure is to use a plane in various positions to create a intersection with solids.
Started with a cylinder.

@Carl Love 
Can determine from an existing procedure its "level", but what it's relation to a printlevel? 

 

myProcedure := proc()
    local currentDepth,  innerProcedure;
    currentDepth := kernelopts(level);
    printf("Current evaluation depth: %d\n", currentDepth);
    
    # Nested procedure to demonstrate depth change
    innerProcedure := proc()
        local innerDepth;
        innerDepth := kernelopts(level);
        printf("Inner procedure evaluation depth: %d\n", innerDepth);
    end proc;
    
    innerProcedure(); # Call the nested procedure
end proc:

# Call the main procedure
myProcedure();

Current evaluation depth: 23
Inner procedure evaluation depth: 44

 

Simple debugging handling for a procedure
trace ? for this example. 

printlevel:= 1;

1

(1)

printlevel:= 10;

10

(2)

check_printlevel = kernelopts('printlevel');

check_printlevel = 10

(3)

printlevel:= 1;

1

(4)

 

 

restart

max_eigenwaarde := proc(a::matrix)
  local eigenwaarden, max_eigenw, i;
  eigenwaarden := linalg[eigenvals](a);
  max_eigenw := eigenwaarden[1];
  for i from 2 to nops(eigenwaarden) do
     if max_eigenw < eigenwaarden[i] then
     max_eigenw := eigenwaarden[i];
     end if;
  end do ;
max_eigenw;
end proc:

 

A:=linalg[matrix](2,2,[[1,2],[0,3]]);

array( 1 .. 2, 1 .. 2, [( 2, 1 ) = (0), ( 2, 2 ) = (3), ( 1, 1 ) = (1), ( 1, 2 ) = (2)  ] )

(5)

max_eigenwaarde(A);

Error, (in max_eigenwaarde) invalid input: nops expects 1 argument, but received 2

 

 

trace

(6)

tracelast; #### see line number 3, detected error

 max_eigenwaarde called with arguments: A
 #(max_eigenwaarde,3): for i from 2 to nops(eigenwaarden) do ... end do;

 

Error, (in max_eigenwaarde) invalid input: nops expects 1 argument, but received 2

 

 locals defined as: eigenwaarden = (1, 3), max_eigenw = 1, i = i

 

showstat(max_eigenwaarde);


max_eigenwaarde := proc(a::matrix)
local eigenwaarden, max_eigenw, i;
   1   eigenwaarden := linalg[eigenvals](a);
   2   max_eigenw := eigenwaarden[1];
   3   for i from 2 to nops(eigenwaarden) do
   4       if max_eigenw < eigenwaarden[i] then
   5           max_eigenw := eigenwaarden[i]
           end if
       end do;
   6   max_eigenw
end proc
 

 

other approach

debug(max_eigenwaarde): max_eigenwaarde(A);

{--> enter max_eigenwaarde, args = A

 

1, 3

 

1

 

<-- ERROR in max_eigenwaarde (now at top level) = invalid input: %1 expects %2 argument, but received %3, nops, 1, 2}

 

Error, (in max_eigenwaarde) invalid input: nops expects 1 argument, but received 2

 

undebug(max_eigenwaarde):

Information by a higher value of printlevel: 10

printlevel:= 10:

max_eigenwaarde(A);

{--> enter \`type/matrix\`, args = A

 

[1 .. 2, 1 .. 2]

 

<-- exit \`type/matrix\` (now at top level) = true}

 

{--> enter max_eigenwaarde, args = A

 

{--> enter linalg:-eigenvals, args = A

 

2

 

array( 1 .. 2, 1 .. 2, [( 2, 1 ) = (0), ( 2, 2 ) = (-3+lambda), ( 1, 1 ) = (-1+lambda), ( 1, 2 ) = (-2)  ] )

 

(-1+lambda)*(-3+lambda)

 

[1, 3]

 

1, 3

 

<-- exit linalg:-eigenvals (now in max_eigenwaarde) = 1, 3}

 

1, 3

 

1

 

<-- ERROR in max_eigenwaarde (now at top level) = invalid input: %1 expects %2 argument, but received %3, nops, 1, 2}

 

 max_eigenwaarde called with arguments: A
 #(max_eigenwaarde,3): for i from 2 to nops(eigenwaarden) do ... end do;

 

Error, (in max_eigenwaarde) invalid input: nops expects 1 argument, but received 2

 

 locals defined as: eigenwaarden = (1, 3), max_eigenw = 1, i = i

 

printlevel:= 1 ;

1

(7)

trace ?

restart;

max_eigenwaarde := proc(a::matrix)
#option trace;  
local eigenwaarden, max_eigenw, i;
  eigenwaarden := linalg[eigenvals](a);
  max_eigenw := eigenwaarden[1];
  for i from 2 to nops(eigenwaarden) do
     if max_eigenw < eigenwaarden[i] then
     max_eigenw := eigenwaarden[i];
     end if;
  end do ;
max_eigenw;
end proc:

 

A:=linalg[matrix](2,2,[[1,2],[0,3]]);

array( 1 .. 2, 1 .. 2, [( 2, 1 ) = (0), ( 2, 2 ) = (3), ( 1, 1 ) = (1), ( 1, 2 ) = (2)  ] )

(8)

max_eigenwaarde(A);

Error, (in max_eigenwaarde) invalid input: nops expects 1 argument, but received 2

 

trace(max_eigenwaarde);#printlevel : 1

max_eigenwaarde

(9)

 

restart;

check_printlevel = kernelopts('printlevel');

check_printlevel = 1

(10)

printlevel:= 3;

3

(11)

max_eigenwaarde := proc(a::matrix)
#option trace;  
local eigenwaarden, max_eigenw, i;
  eigenwaarden := linalg[eigenvals](a);
  max_eigenw := eigenwaarden[1];
  for i from 2 to nops(eigenwaarden) do
     if max_eigenw < eigenwaarden[i] then
     max_eigenw := eigenwaarden[i];
     end if;
  end do ;
max_eigenw;
end proc:

 

A:=linalg[matrix](2,2,[[1,2],[0,3]]);

array( 1 .. 2, 1 .. 2, [( 2, 2 ) = (3), ( 2, 1 ) = (0), ( 1, 2 ) = (2), ( 1, 1 ) = (1)  ] )

(12)

max_eigenwaarde(A);

 max_eigenwaarde called with arguments: A
 #(max_eigenwaarde,3): for i from 2 to nops(eigenwaarden) do ... end do;

 

Error, (in max_eigenwaarde) invalid input: nops expects 1 argument, but received 2

 

 locals defined as: eigenwaarden = (1, 3), max_eigenw = 1, i = i

 

trace(max_eigenwaarde);# ?

max_eigenwaarde

(13)
 

 

Download vooorbeeld_voor_mapleprimes_post_debuhgging.mw

procedure 

@mmcdara 
Thanks, if the procedure contains : loop or if statement : printlevel : +1
For each procedure call : printlevel : +5, that is for recursion programming, so each iteration for that requires a procedure call. 

@janhardo 

The printlevel depends on the complexity of the procedure. 

First 30 31 32 33 34 35 36 Last Page 32 of 73