Carl Love

Carl Love

28025 Reputation

25 Badges

12 years, 311 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

Functions that don't appear in the ODE system can also be plotted with odeplot. So, you can do

plots:-odeplot(Sol, [P,V](x), x= 0..10)

even though only P(x) appears in the differential equation(s). So, there's no need to change your original ODE(s).

The above command plots one curve, V vs P, not two separate curves.

Just to summarize the essential point, which may be difficult to see amidst the dense numeric code: The parameter of animate is inherently real-valued; it must be somehow converted to an integer before being used as an index to your table SOLNSuy. The alternative to animate is to create an indexable container of static plots and pass it to display(..., insequence).

What you found, unapply, is the most widely recommended way to do it.

The solution is simply the obvious: f(x/a).

I don't understand exactly why what you had doesn't work, but I strongly prefer using eval rather than assign. By simply making that change, it now works. Replace your last line of code with

Sol:= {};
for i from 0 to N do   
    Sol:= Sol union {dsolve({cond[1][i], eval(equ[2][i], Sol)}, {f[i](x)})}
end do;

It can be done like this:

C:= lcoeff(y^2 - x^2/y, order= plex(x,y), 't'):
C*t;

                       -x^2/y

In many top-level Maple commands, the concept of polynomial is generalized a bit to allow for negative exponents. 

You're making two mistakes: The first is mixing up integer and polynomial computation; the second is mixing up exact and floating-point computation. 

Integer vs polynomial: You're making exactly the same mistake as you were making regarding gcd. The mod commands (there's a whole family of them) are intended primarily for polynomials and matrices over finite rings (including finite fields). The command for computing the remainder of integer division is irem. Do you see a pattern here? Top-level commands for pure-integer arithmetic begin with i. Your command x mod 3 returns x because x is a polynomial; it's not a placeholder for an integer.

Exact vs floating-point: Neither of these exact commands is appropriate for use as the first argument to plot, which is necessarily based on floating-point computation. 

Replace sum with add. The problem with sum is that the derivative of u[i] is evaluated before has a value. Since u[i] hasn't been defined in terms of x for generic i, its derivative is 0. On the other hand, add evaluates its index variable to a value in the specified range before evaluating its expression. 

One is tricked into believing that the first assembly in VV's Answer is a right triangle, making the area 32-1/2. But actually that assembly is a quadrilateral. The slope of the hypotenuse of the green triangle is 2/5, while that of the red triangle is 3/8. The difference of the angles is only about 1.2 degrees, or a relative difference of about 6%. Thus the supposed hypotenuse of the overall triangle is actually 2 sides of a quadrilateral, and its area is actually 32.

This is not a bug. The 2 represents the precision at which the computations are done, not the precision of the final result. The number 1014.1 can't be represented adequately in 2 digits.

Here's how to do it.
 

restart:

After running the next command, follow the dialog to load your Excel file. Just take the defaults for the questions after the first.

XL:= ExcelTools:-Import();

Matrix(6, 7, {(1, 1) = "Re\Bn", (1, 2) = 0., (1, 3) = 1.0, (1, 4) = 10.0, (1, 5) = 100.0, (1, 6) = 1000.0, (1, 7) = "X", (2, 1) = 1.0, (2, 2) = 28.5395, (2, 3) = 15.15575, (2, 4) = 4.04, (2, 5) = 1.8326534653465347, (2, 6) = 1.5436413586413587, (2, 7) = 0., (3, 1) = 10.0, (3, 2) = 2.8535, (3, 3) = 2.739090909090909, (3, 4) = 2.222, (3, 5) = 1.6827090909090907, (3, 6) = 1.5299257425742574, (3, 7) = 0., (4, 1) = 100.0, (4, 2) = .2855, (4, 3) = .2985148514851485, (4, 4) = .40409090909090906, (4, 5) = .9255, (4, 6) = 1.4047272727272728, (4, 7) = 0., (5, 1) = 1000.0, (5, 2) = 0.325e-1, (5, 3) = 0.3346653346653347e-1, (5, 4) = 0.45396039603960395e-1, (5, 5) = .16818181818181815, (5, 6) = .7725, (5, 7) = 0., (6, 1) = "Y", (6, 2) = 0., (6, 3) = 0., (6, 4) = 0., (6, 5) = 0., (6, 6) = 0., (6, 7) = 0.})

R:= upperbound(XL,1)-2: #rows of data
C:= upperbound(XL,2)-2: #columns of data

XYZ:= Matrix( #Reform as 3-column Matrix with X, Y, Z columns.
    (R*C, 3),
    (i,j)->
        local r:= iquo(i-1,C)+2, c:= irem(i-1,C)+2:
        `if`(j=1, XL[1,c], `if`(j=2, XL[r,1], XL[r,c]))
);

_rtable[18446746137574600942]

Model:= (A+B*x)/(x+y):

ModelFit:= Statistics:-LinearFit(Model, XYZ, [x,y]);

HFloat(28.586144326529155)/(x+y)+HFloat(1.5517626243136244)*x/(x+y)

plots:-display(
    plots:-pointplot3d(XYZ, symbol= solidsphere, symbolsize= 24, color= red),
    plot3d(
        ModelFit, x= (min..max)(XYZ[..,1]), y= (min..max)(XYZ[..,2]),
        transparency= 0.4
    ),
    axis[3]= [mode= log]
);

 


 

Download 3dModelFit.mw

The following is a variation of VV's procedure that uses the low-level operations of LinearAlgebra:-Modular for efficiency. I believe that it'll run about 2-1/2 times faster---not a huge improvement, but perhaps worthwhile. Please test it on a matrix known to be MDS.

IsMDS:= proc(
    A::Matrix(square),
    r::And(posint, satisfies(r-> irem(upperbound(A,1), r) = 0))
)
uses LAM= LinearAlgebra:-Modular;
local
    n:= iquo(upperbound(A,1), r), 
    rng:= t-> (t-1)*r+1..t*r,
    M:= LAM:-Mod(2, A, float[8]),
    k, kr, P, ip, jp, det
;
    for k to n do
        kr:= k*r;
        P:= combinat:-choose(n,k);
        for ip in P do 
            for jp in P do
                LAM:-RowReduce(
                    2, M[rng~(ip), rng~(jp)], kr$3, 'det', 0$4, false
                );
                if det=0 then return false fi
            od
        od
    od;
    true
end proc
:    

 

My try:

restart:
d:= proc(m::integer)
option remember;
local i;
    -expand(add(xi[i]*thisproc(m-i+1), i= 2..m))
end proc:
d(1):= 1:

DD:= m-> rtable((1..m)$2, (i,j)-> d(j-i+1), subtype= Matrix): 
DD(4);

 

The command gcd is meant for polynomials. As polynomials, and have no common factors, so their GCD is 1. The command for the GCD of integers is igcd.

You make ab, and x the parameters of a procedure and pass to them two expressions and a variable name. To do RK4, we also need an initial condition, a final value of x, and a number of steps. Like this:

MyRK4:= proc(
    a::algebraic, b::algebraic, x::name,
    x0::realcons, y0::realcons, xf::realcons, n::posint
)
local y, h:= (xf-x0)/n, k;
    dsolve(
        {diff(y(x),x) = 10*(y(x)-a)/b, y(x0) = y0}, numeric,
        'method'= 'classical'['rk4'], 'stepsize'= h,
        'output'= Array(1..n, k-> x0+k*h)
    )[2][1]
end proc
:
MyRK4(ln(x), x, x, 1, 1, 2, 10);

 

First 119 120 121 122 123 124 125 Last Page 121 of 395