Carl Love

Carl Love

28065 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Use procedure-form input for the ODE. Give the procedure option remember. When the integration is done, the indices of the table will contain precisely the values of the independent variable at which the ODE was evaluated. Here is the command to extract the list of indices, assuming that is your procedure of the ODE:

T:= [indices(op(4, eval(F)), 'nolist')];

No, not exactly, because that value depends on both the input lists and the model being fitted, particularly its number of fitted parameters, k, since n-k is the degrees of freedom. You can get the LinearFit  command to return the residual standard error like this:

#Create two random data lists, just for example:
(X,Y):= 'LinearAlgebra:-RandomVector(9)' $ 2:

#Fit two parameters, the usual intercept and slope:
L:= Statistics:-LinearFit([1, x], X, Y, x, output= solutionmodule):
L:-Results(residualstandarddeviation);
                        59.3362504084196

#Fit quadratic model (3 parameters) to the same data:
L:= Statistics:-LinearFit([1, x, x^2], X, Y, x, output= solutionmodule):
L:-Results(residualstandarddeviation);
                        50.7377653987838

The above shows that the value that you want isn't a function of X and Y alone. If you want to restrict attention to the case of just fitting a line, then a command to do it "on its own" could be easily constructed (it'd be a one-liner) from the above.

There is a Maple command dedicated to this type of computation: evala(Norm(...)).

evala(Norm(x - (-4+I)));
      x^2 + 8*x + 17

This command is much more general than complex conjugates. So, if the question were changed to "Let p(x) be an integer polynomial of degree 6 such that p(sqrt(2+sqrt(2))) = 0. Find a 4th-degree integer polynomial factor of p(x)."

evala(Norm(x - sqrt(2+sqrt(2))));
      x^4 - 4*x^2 + 2

Of course, you should also know how to do it Kitonum's way, and how to do it that way by hand.

I think that this is the generalization to vector-mode operations that you're asking about:

Suppose that ex is an algebraic expression[*1] with a single free variable[*2] x. To be concrete, I'll use

ex:= sin(x^2) + 3*x;

but it doesn't matter how complicated ex is nor how many separate commands were needed to build it. I can make a function (aka procedure or operator) named f equivalent to ex by binding[*3] x with the command unapply:

f:= unapply(ex, x);

Now, I want to specify a "list" or "vector" xVals of numeric values for x, let's say from 3 to 5 with 0.1 spacing:

xVals:= < seq(3..5, 0.1) >: 

Note the angle brackets <...>, which make it what Maple calls a Vector. You could just as well use square brackets [...], as you did above, which make it what Maple calls a list

Now I want to evaluate ex (using f) at every value in xVals and call that yVals. This part is amazingly easy, and it's the crux of what your Question is about:

yVals:= f~(xVals):

Note that there's no need to include the ~ symbol anywhere in the original expression. It's needed only one time for this process. So any algebraic expression can be made to operate on vectors without needing to edit the original expression. Also, there's no need to make an a priori definition of x as a vector.

The pairs can be plotted with

plot( < xVals | yVals >);

This is by no means the most-general generalization that can be made; there's many layers of generalization that could be put on top of this. Indeed, actually ex doesn't need to be an algebraic expression, and it can have any number of free variables. I only put those restrictions on as an aid to learning this material.

Definitions:

[*1]By algebraic expression, I mean any expression, possibly containing some free variables, such that if its free variables were given complex-number values, the expression would represent a single extended-complex number; and there exists some algorithm, at least in theory, for getting its decimal value at least to some finite number of decimal places.

In using the word algebraic, I don't mean to exclude transcendental functions, even non-elementary ones; but I do mean to exclude vectors, matrices, sets, lists, equations, inequations, etc., and expressions that evaluate to them -- anything that can't be evaluated to a single extended-complex number.

[*2]By free variable, I mean a variable in an expression which doesn't have an assigned value but which could be assigned a value such that the expression is still meaningful. So, note that being free is not an inherent property of the variable; it is determined with respect to an expression. A variable may be free in an expression and that expression embedded in a larger expression such that the variable is not free in the larger expression (example in next definition below).

[*3]Binding a variable means taking an expression with a free variable and embedding it in a larger context in which it is no longer free. As a nontrivial example, x^2+3*x is an expression with a free variable x. If I express (without evaluating) the indefinite integral with respect to x, as in Int(x^2 + 3*x, x), that's binding x (since x can no longer be meaningfully assigned a value before the integral is evaluated). Due to an unfortunate idiosyncracy of English, after its binding, a variable is called a bound variable, not a "binded" variable. 

Like this:

r0:= -4+I:
expand((x-r0)*(x-conjugate(r0)));

      

Note that rather than i is Maple's default symbol for sqrt(-1), though it can be changed to any symbol that you want.

While I strongly recommend that you learn the plot command recommended by MMcDara, as it is the most versatile such command, in this case the highly specialized FunctionPlot may be more suited to your purpose:

Student:-Calculus1:-FunctionPlot(3*x^3-2*x^2+5*x-7, x= -3..6);

And I don't mean to suggest that there's anything wrong with using plot for this! Indeed, I'd use plot if I were doing the problem myself; because I know all of its options, I'd annotate the plot as I saw fit rather than using the pre-set (although still customizable) annotations offered by FunctionPlot.

The one line of code that you show, together with the error message, makes it seem as if you're trying to modify SIRvector before it has even been defined. Surely that can't work.

If you need a more-thorough Answer, then you'll need to upload more-complete code.

Maple does not understand your use of square brackets; however, your usage is not so far from valid that Maple will say so outright.

Do this:

j:= (n,z)-> sqrt(2)*sqrt(Pi/z)*BesselJ(n + 1/2, z)/2;
plot(j(1,z), z= 0..25);

Assuming that you're only interested in the computed results rather than a symbolic representation of the spline function, the following is more computationally efficient and shorter codewise:

x1:= Vector(
   [0.8e-1, .28, .48, .68, .88, 1, 1.2, 1.4, 1.6, 1.8, 2, 
    2.2, 2.4, 2.6, 2.8, 3, 3.2, 3.4, 3.6, 3.8, 4, 4.2
   ], 
   datatype= hfloat
):
y1:= Vector(
   [-10.081, -10.054, -10.018, -9.982, -9.939, -9.911, -9.861, -9.8, -9.734, -9.659, -9.601, 
    -9.509, -9.4, -9.293, -9.183, -9.057, -8.931, -8.806, -8.676, -8.542, -8.405, -8.265
   ],
   datatype= hfloat
):
x2:= log10~(2*10^~x1):
y2:= CurveFitting:-ArrayInterpolation(x1, y1, x2, method= spline):
plot([<x1|y1>, <x2|y2>], style= [point,line], legend= [original, interpolated]);

As is often possible in Maple, the above code treats all vectors as fundamental units of data, without any need for indexing or paying any attention to the number of elements in the vectors.

To understand better what's going on here, it helps to look at the exact values. I parameterized your sum by replacing (-1)^n by a^n and summed it symbolically for those a for which it converges (which, of course, doesn't include a = -1):

sum(a^n*n^2/(n+1), n= 1..infinity) assuming abs(a) < 1:
simplify(%);
                                   2      2    
                -ln(-a + 1) (a - 1)  + 2 a  - a
                -------------------------------
                                   2           
                          a (a - 1)            

Then "analytically extend" that solution by using a outside the original restrictions:

eval(%, a= -1);
                            3        
                          - - + ln(2)
                            4        
evalf(%);
                         -0.0568528194

That decimal value is the same as you got from your evalf(Sum(...)), and the corresponding exact value is ln(2) - 3/4.

Using Alt - and Alt + allows for the zoom factor to be any multiple of 25% between 50% and 400%. That's 15 levels, which is more than are listed on the menu (7 levels). But it would be nice to have finer gradations for the values close to 100%, such as 90% and 110%.

The following treatment gives more flexibility using code of about the same complexity:

  • The degree of the curves is determined by the number of control points; it need not be cubic;
  • The dimension is determined by the number of elements of the control points; it can be any positive integer;
  • Plot options can be passed in.
restart;
Bezier:= proc(P::seq(list(realcons)))
local 
   i, j, t, n:= nops([P]), d:= max(3, nops~([P])[]), #defaults to 3D. 
   #Implicit 0-padding is intentional; it allows easy switching between dimensions:
   V:= rtable~(1..d, [P]) 
;
   seq(unapply(add(V[j][i]*binomial(n-1,j-1)*(1-t)^(n-j)*t^(j-1), j= 1..n), t), i=  1..d)
end proc:

Bezier_plot3d:= proc(P::seq(list(realcons)))
local t;
   plots:-spacecurve([Bezier(P)[..3](t)], t= 0..1, _rest)   
end proc:

Example:

Bezier([2,5], [3.5,4], [3.5,1], [2,0]);

Bezier_plot3d([2,5], [3.5,4], [3.5,1], [2,0], thickness= 4, orientation= [-90,0]);

Here's a somewhat generalized treatment of these situations:

  • a system of low-degree multivariate polynomials,
  • the dimension (algebraic, not topological) of the complex solution set is higher than that of the real solution set,
  • only the real solutions are wanted.

This is similar to Tom's solution, but doesn't use assume (which usually causes solve to complain); and to Christian's, but doesn't use (which is totally bizarre).

restart;
Eqns:= {x^2+y^2+z^2-4*x+6*y-2*z-11 = 0, 2*x+2*y-z = -18};
n:= nops(Eqns);
V:= indets(Eqns, And(name, Not(constant)));
sol:= [solve(Eqns, V[..n], explicit)]; #So, same number of eqns as solved-for vars
#Solve for imaginary parts of free vars to be 0:
free_v:= map(solve, ((evalc@Im)~)~(sol), V[n+1..]);
#Re-evaluate original solution(s) with those free-var values:
{(eval~(sol, free_v) union~ free_v)[]};

This treatment allows for the possibility of multiple solutions. The first solve result is put in a list so that the free-variable solutions are matched with the correct primary solution.

There may not be any situations where this result is better than that from parametricreal.

Like this:

restart:
PDE1:= diff(m(t,x),t)+diff((u(t,x)^2-(diff(u(t,x), x))^2)*m(t,x), x) = 0;
PDE2:= eval(PDE1, m(t,x)= u(t,x)-diff(u(t,x), x,x)); 
ODE:= convert(simplify(eval(PDE2, u(t,x)= U(x-a*t)), {x-a*t= y}), diff);

 

The main problem with your code is that the initialization of the product to 1 is inside the for loop. This should be easy for you to correct. Let me know if you need further help with that.

An alternative is the simpler

mul(ArrayTools:-Diagonal(M)),

where is the Matrix.

First 147 148 149 150 151 152 153 Last Page 149 of 395