Carl Love

Carl Love

28070 Reputation

25 Badges

13 years, 28 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

Student:-Calculus1:-VolumeOfRevolution(
     x^2, sqrt(x), x= 0..1, axis= horizontal , distancefromaxis= -1,
     output= animation, partition= 40,
     volumeoptions= [color= yellow]
);

If you you want to do the rotation about the line x = -1 by the washer method, then you need to integrate with respect to y. Because your functions are inverses of each other, the command is the same as above with x changed to y, which in reality changes nothing. More interesting is to do it by shells. For this change the axis option to axis= vertical.

To get a Maple plot similar to the kgraph plot, use the view option to restrict the view:

plot(A[.., 1], A[.., 2], view= [-1.5e-9..2.5e9, -2..2]);

Since you are using (1D) Maple Input, it is incorrect to define a function (procedure) by

g(t):= f(x(t), alpha(t), beta(t))

The correct syntax is

g:= t-> f(x(t), alpha(t), beta(t)).

If you use the "g(t):=", then you are defining an expression that will only work when the is explicitly used. That is, g(t) will work, but g(1.0) will not.

 

Example:

Ell:= x^2+4*y^2-2*x-16*y+13=0:
# Make sure the x and y ranges are large enough to contain the entire ellipse by  viewing the plot.
plots:-implicitplot(Ell, x= -5..5, y= -5..5, gridrefine= 3);
A:= op([1,1], %); #Extract point data array from plot.

Let's say that the function that you want to save is named F. Then do

save F, "C:/users/carl/desktop/F.map":
restart:

read "C:/users/carl/desktop/F.map":

This process is can be used to save any variables, not just functions.

Since you are using select, I assume that you want to select the terms that have second derivatives rather than selecting the derivatives themselves. To do this, we convert the expression to D form, do the select, then convert back to diff form:

convert(select(has, convert(eq[1], D), D@@2), diff);

I'm still thinking about your second question.

First the operation `^` of 10.2^20 is carried out by "automatic simplification", as is all basic arithmetic. So it is done in the 10-digit default environment. Then that result, already rounded to 10 digits, is passed to evalf. The automatic simplifcation is not delayed by the "special evaluation rules" of evalf. However, if you change the exponentiation into a procedure call, then it can be delayed.

use `^`= ((x,y)-> :-`^`(x,y)) in evalf(10.2^20, 50) end use;

The residual sum of squares that you got applies to the underlying linear model. The help at ?ExponentialFit has this caveat:

However, it is important to note that these options, including the output option for obtaining additional results, apply to the transformed model.

LinearFit([1,x], X, ln~(Y), x, output= residualsumofsquares);

0.00216641200893470

To get the residual sum of squares for the exponential model, you'll need to do something like

F:= unapply(ExponentialFit(X, Y, x), x):
add((F(X[k])-Y[k])^2, k= 1..numelems(X));

 

 

 

 

 

 

Please see my more-detailed Answer to your related Question. Addressing your Question here: p is a local variable of procedure quicksort. Thus there is a separate copy of p for each invocation of quicksort. The value of this local copy cannot change between the two recursive calls to quicksort. Maple is essentially the same as any other modern programming language in this regard.

You can use an inert %piecewise with empty strings for the conditions. Like this:



restart:

%piecewise(``, 3*x+2*y=7, ``, x+4*y= 3);

"`%piecewise`(,3 x+2 y=7,,x+4 y=3)"



Download Inert_piecewise.mw

 

Since your program works correctly, it is difficult for me to comment. But here is a way to increase your understanding of the program so that you can answer your own question. Rather than dealing with the overwhelming amount of redundant information provided by trace, use userinfo statements to display useful information. Also, indent your code. Here is your code indented and instrumented with userinfo statements. I included kernelopts(level) so that you can see the recursion depth: 23 is the first level, 49 the second, and 75 the third.

I also changed your array to a Vector since array is deprecated (no longer used in new code).

quicksort:= proc(A::Vector(numeric), m::nonnegint, n::nonnegint)
local
     partition:= proc(m::nonnegint, n::nonnegint)
     local i:= m, j:= n, x:= A[n];
          while i < j do
               if A[i] > x then
                    A[j]:= A[i];
                    j:= j-1;
                    A[i]:= A[j]
               else
                    i:= i+1
               end if
          end do;
          A[j]:= x;
          j
     end proc,
     p,k
;
     userinfo(
          6, quicksort, NoName,
          sprintf(
               "A = [%d], m=%d, n=%d, level=%d",
               A, m, n, kernelopts(level)
          )
     );

     if m < n then
          p:= partition(m,n);
          userinfo(6, quicksort, NoName, "p =", p);
          quicksort(A,m,p-1);
          quicksort(A,p+1,n)
     end if;
     A
end proc:

infolevel[quicksort]:= 6:
a:= < 2,4,1,5,3 >^%T:
quicksort(a,1,5);

A = [2 4 1 5 3], m=1, n=5, level=23
p = 3
A = [2 1 3 5 4], m=1, n=2, level=49
p = 1
A = [1 2 3 5 4], m=1, n=0, level=75
A = [1 2 3 5 4], m=2, n=2, level=75
A = [1 2 3 5 4], m=4, n=5, level=49
p = 4
A = [1 2 3 4 5], m=4, n=3, level=75
A = [1 2 3 4 5], m=5, n=5, level=75
           

That should be

f1:= eval(a1(t), sol1);

not f1(t).

Here I do the 3d plots using dsolve's parameters option. Then I paste separate plots of x(t) and y(t) together with display.

# System of two equations with a parameter:
Sol:= dsolve(
     {diff(x(t),t) = k, x(0) = 1, diff(y(t),t) = k, y(0) = -1},
     numeric, parameters= [k]
);

# x(t) and y(t) are necessarily computed at the same time. The
# procedure SOL is to avoid redoing those computations when they
# are plotted separately.
SOL:= proc(k,t)
option remember;
     Sol(parameters= [k]);
     Sol(t)
end proc;

X:= (k,T)-> eval(x(t), SOL(k,T)):
Y:= (k,T)-> eval(y(t), SOL(k,T)):

# Plot X and Y individually. Save plots to variables.
P1:= plot3d(X, -2..2, -2..2):
P2:= plot3d(Y, -2..2, -2..2):

# Piece together plots with `display`.
plots:-display([P1,P2], axes= boxed);

I have a feeling that this is not exactly what you want, but it may be the best that is possible: Use Print Preview from the File menu.

Here's an example where I compute the order of convergence of Newton's method applied to a specific function.

Newton:= proc(
     f::operator,  #function in operator form
     x0::complexcons, #initial guess of root r such that f(r)=0
     n::posint  #number of iterations
)
local
    x, N:= unapply(simplify(x - f(x)/D(f)(x)), x),
    R:= Vector(n, [N(x0)]),  
    k
;
    for k from 2 to n do
         R[k]:= N(R[k-1])
    end do;
    R #return vector of iterates
end proc:
 
#Example function:
f:= x-> x^3-1:
true_root:= 1:
Digits:= 100:
n:= 8:
R:= Newton(f, .5, n):
#Compute the logs of the absolute errors.
lnE:= map(x-> ln(abs(x-true_root)), R):
Digits:= 15:
seq(lnE[k+1]/lnE[k], k= 1..n-1);

The sequence above appears to be converging to 2. That's the order of convergence.

First 303 304 305 306 307 308 309 Last Page 305 of 395