janhardo

700 Reputation

12 Badges

11 years, 44 days

MaplePrimes Activity


These are replies submitted by janhardo

@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. 

@mmcdara 

Thanks, saw it today the kernel opts with printlevel.

Seemed convenient if a procedure has a printlevel as input and after executing the procedure sets the printlevel back to a default value.

Yes, trace and tracelast with printlevel would be the simplest tools for error detection. 
Tracelast shows the last result of the procedure, but stops when an error is detected and trace also shows this error by the looks of it.
To use tracelast effectively the printlevel must be set to 3

@dharr 
Thanks, that's how it was : the error message gave enough information, but didn't do anything with it.  

@dharr 

Thanks, am relieved that is solved as did not get there properly.
Forgot that the last statement in the procedure shows an outcome.
Should have studied better the structure of input variables of complexplot3d command compared to plot3d command.
Did get some procedures for a complex3dplot working quickly, but that just didn't include further plot options .

Had gotten a plot, I could have concluded ( in retrospect) that 
view=plotview.. tricky ..is it documented?

 

restart;

complex_surface := proc(f, z_range::range(complex))
    
    printf("Complex function f(z) defined.\n");
    printf("Range of z values: %a\n", z_range);
    
    # Plot de complexe functie met complexplot3d
    printf("Plotting complex function...\n");
    print(plots:-complexplot3d(f, z_range, view=[-50..50, -5..5, 0..5], grid=[50,50]));
    
    printf("Plot generated.\n");
    
end proc:

# Definieer de complexe functie f(z) = ln(z)
f := z -> ln(z);

# Definieer het bereik van z-waarden voor de plot
z_range := -50-5*I .. 50+5*I;

# Roep de procedure aan om de plot te genereren
complex_surface(f, z_range);

 

Trying to make this procedure: complex_surface for complex3dplot input suitable for view, orientatation and grid plot options , but do not succeed me yet.
Also showing the plot via print seems strange?
What is going wrong here?

restart;

complex_surface := proc(f, z_range::range(complex), view::list)
    
    printf("Complex function f(z) defined.\n");
    printf("Range of z values: %a\n", z_range);
    
    # Plot de complexe functie met complexplot3d
    printf("Plotting complex function...\n");
    display(plots:-complexplot3d(f, z_range, view = view, grid = [50, 50]));
    
    printf("Plot generated.\n");
    
end proc:

# Definieer de complexe functie f(z) = ln(z)
f := z -> ln(z);

# Definieer het bereik van z-waarden voor de plot
z_range := -50-5*I .. 50+5*I;

# Roep de procedure aan om de plot te genereren
complex_surface(f, z_range, [-50..50, -5..5, 0..5]);

     f := proc (z) options operator, arrow; ln(z) end proc

                z_range := -50 - 5 I .. 50 + 5 I

Complex function f(z) defined.
Range of z values: -50-5*I .. 50+5*I
Plotting complex function...

Error, (in plot3d) unexpected option: [-50 .. 50, -5 .. 5, 0 .. 5] = [-50 .. 50, -5 .. 5, 0 .. 5]

 

@dharr 
Thanks, looks much better your plot

@janhardo 

Both procedures give the same result.
Procedure 2 is not yet as solid as procedure 1 and ease of use, so some adjustments to be made.



ImplicitPlot3D_withCurveProjection(x^2 + y^2 - z, 0, -1.5..1.5, -1.5..1.5, -2..2, t -> cos(t), t -> sin(t), t ->0, 0..2*Pi, 30);



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