Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

If the system of linear equations that you present has a unique solution (which is likely), then the final solution depends entirely on the s-vector b. You could choose b to give the exact solution for x(h), for example! In other words, figuring out a good b to use must be just as difficult as approximating the solution in the first place. Note that the system of equations does not involve b. Or, in more other words, the solution of the system of linear equations doesn't matter. So, either it's a crack-pot method, or your PDF is missing some crucial elements.

What you want cannot be easily done with implicitplot, but it can be easily done by parameterizing the curves and using animatecurve:

common:= color= red, thickness= 5, scaling= constrained, axes= none, paraminfo= false:
plots:-animatecurve([[-cos(t), sin(t), t= 0..Pi], [-cos(t), -sin(t), t= 0..Pi]], common);
plots:-animatecurve([[-3*abs(sin(y)), y, y= Pi..0], [-3*abs(sin(y)), y, y= Pi..2*Pi]], common);

 

The second solve command is missing a comma between its last two equations.

Note the error message:

Error, missing operator or `;`

This indicates a purely syntactic error rather than a mathematical error.

Your IC and BC are already sets, so {IC,BC}, which you pass to pdsolve, is a set of sets rather than a set of equations.

How about this?

restart:
interface(imaginaryunit= _i):
f:= (x,y)-> Re(sqrt(x+_i*y)):
plots:-display(
    plot3d(
        (common:= (
           [seq([x, y, k*f(x,y)], k= [-1,1])], x= -1..1, y= -1..1
        )), 
        grid= [200$2], style= surface, glossiness= 1, transparency= .05, 
        colorscheme= [
            "xyzcoloring", 
            [(x,y,z)-> y^2, (x,y,z)-> abs(x*y), (x,y,z)-> x^2]
        ]
    ),
    plot3d(
        common,
        grid= [25$2], style= wireframe, thickness= 3, 
        colorscheme= [
            "xyzcoloring",
            [(x,y,z)-> 1-y^2, (x,y,z)-> abs(x*y), (x,y,z)-> 1-x^2]
        ]
    ),
    lightmodel= light2, orientation= [55,75,0], projection= .85, axes= frame,
    labels= ['x', 'y', Re(w)]
);

Here's a small wrapper procedure for DEtools:-matrixDE that does everything that that does, then solves for the integration constants given the initial conditions, and then returns the solution in Matrix and Vector form. The wrapper accepts the options used by maxtrixDE---method and solution---if they are placed at the end of the command.

restart:

A:= <1,-2; 4,-5>;
b:= <3,7>;
t__init:= 1;
ics:= <f1,f2>;

Matrix(2, 2, {(1, 1) = 1, (1, 2) = -2, (2, 1) = 4, (2, 2) = -5})

Vector(2, {(1) = 3, (2) = 7})

t__init := 1

Vector[column](%id = 18446746467426949350)

MatrixDEwithIC:= proc(
   A::Matrix, b::Vector, t::name, ics::Vector,
   t0::algebraic:= 0,
   {output::identical(list, inert):= inert}
)
local S, P, C, Sol:= DEtools:-matrixDE(A, b, t, _rest);
    S:= convert(Sol[1], Matrix);
    P:= convert(Sol[2], Vector)^+;
    C:= LinearAlgebra:-LinearSolve(eval(<S|ics-P>, t= t0));
    `if`(output=inert, S %. C %+ P, [S,C,P])
end proc
:

Sol:= MatrixDEwithIC(A, b, t, ics, t__init);

`%+`(`%.`(Matrix(2, 2, {(1, 1) = exp(-t), (1, 2) = exp(-3*t), (2, 1) = exp(-t), (2, 2) = 2*exp(-3*t)}), Vector(2, {(1) = (2*f1+1-f2)/exp(-1), (2) = -(1/3)*(3*f1+4-3*f2)/exp(-3)})), Vector(2, {(1) = 1/3, (2) = 5/3}))

Verify that it's the correct solution:

simplify~(value(eval(Sol, t= t__init)));

Vector(2, {(1) = f1, (2) = f2})

simplify~(diff~(value(Sol), t) - (A.value(Sol)+b));

Vector(2, {(1) = 0, (2) = 0})

Same solution with list-form output:

MatrixDEwithIC(A, b, t, ics, t__init, output= list);

[Matrix(2, 2, {(1, 1) = exp(-t), (1, 2) = exp(-3*t), (2, 1) = exp(-t), (2, 2) = 2*exp(-3*t)}), Vector(2, {(1) = (2*f1+1-f2)/exp(-1), (2) = -(1/3)*(3*f1+4-3*f2)/exp(-3)}), Vector(2, {(1) = 1/3, (2) = 5/3})]

 

 

Download MatrixDEwithIC.mw

My procedure also converts the output from matrixDE from the cruddy old-style array format to the modern Matrix and Vector format.

Your expected answers are transposes of what they should be, right?

And you seem too have ignored the advice from the Answers to your previous Question.

Anyway, the transposes of your expected answers can be obtained like this:

restart:
n:= 2:
X:= Vector(n, symbol= x);
W:= Matrix(n$2, symbol= w);
V:= W.X;
seq(diff~(v,W), v= V);

Of course, these can be transposed if you want.

Continuing with Preben's fine advice, you should investigate initial conditions x(0) = c, where c is between a and b/2. This is the middle band, where the more-interesting (and usually more-practical) solutions lie. 

The issue is not that you're trying to differentiate a matrix. Rather, the issue is that you're differentiating with respect to x, a vector, not a single variable. Use Gradient instead of diff:

restart:
x:=<x1,x2>;
W:=<<w11, w12>|<w21, w22>>;
Cal:= (W.x)^%T.(W.x);

VectorCalculus:-Gradient(Cal, [seq(x)]);

Note that I've made x a vector rather than a matrix, and this makes Cal a scalar rather than a one-element matrix.

The issue is simply a misplaced parenthesis, as pointed out by Tom. The purpose of this Answer is to show you two ways to construct more robustly so that perhaps you would've been able to figure that out just from the error message. Your L:= proc(N) N end is not really an identity function; rather, it's a projection function of its first argument. Note that L(1,2) returns 1. Here are two ways to make better:

1. L:= proc(N, $) N end proc: This makes a true one-argument identity function: Any attempt to pass more (or less) than one argument will give an error message. So, the error message from your plot command would've been:

Error, invalid input: too many and/or wrong type of arguments passed to L; first unused argument is k = 0 .. 10

I think that it's obvious from that message that misplaced parentheses are the issue.

2. L:= ()-> args: This makes a true identity function of an arbitrary number of arguments: All arguments are returned. The error message would've been:

Error, (in plot) incorrect first argument [min(5, max(-5, 5^(10*x)+5^(x*k))), k = 0 .. 10]

In this case, the special evaluation rules of seq prevent it from seeing the k= 0..10 as its optional second argument because that expression is part of the result from L. L hasn't yet been evaluated; that's the "special" part. So, seq sees the call to as its sole argument, and it does what it usually does when it only has one argument, which is kind of trivial in this case: It returns the operands of L, which are the arguments. It's just a coincidence that this is what L would've done anyway. Those special evaluation rules could be made normal by replacing seq with (value@%seq). I'm not suggesting that you do this, because it's obvious that you didn't intend for k= 0..10 to be passed to L anyway. Nonetheless, this modification does give the correct plot.

The command is ssystem. See its help page (?ssystem). If the result is a number in string form, use parse to make it a number. I think that it'd be preferable (and perhaps necessary) to make your shell commands into a single command. The assignment to result within the shell seems superfluous. So, for example,

Result:= ssystem("`python model.py 1 2 3 4 5 6 7 8 9 10`"); #Inner quotes may not be needed.
if Result[1]=0 then result:= parse(Result[2]) fi;

You may also be interested in Maple's built-in Python interpreter. See ?Python.

No, there's no software that can do that.

First, you need to choose a name for the independent variable. I chose x. Then

dsolve({diff(y(x),x$2)-y(x), y(0)=0, y(1)=1})

The returned result is obviously equivalent to sinh(x)/sinh(1), but if you want Maple to express it in this form, a few extra steps are needed.

I think that using the method= custom option of Sample means that the sampling procedure to be used should be supplied as the RandomSample option of the Distribution command.

I propose the following algorithm for generating a random sample of size n from MIXTURE:

1. Generate a sample S of size from Uniform(0,1).
2. Count members of S less than p. Call this n1, and let n2:= n - n1.
3. Generate samples S1 and S2 of sizes n1 and n2 from U1 and U2, respectively.
4. Return the concatenation of S1 and S2 in the appropriate rtable format.

This should work for any U1 and U2, regardless of whether they're uniform or whether their supports are disjoint or overlapping.

Edit: I just saw that you proposed a sampling method that uses solve. I think that the above will be faster because it's purely numeric.

Where did you find RandomSampleSetup

There are eight simple algorithms (really just interpolation formulas) that Maple can use for quantiles of raw data, including quartiles. These are documented on help page ?QuaNtile (not ?QuaRtile), but the same method options can be used with either command. To get 2.5, do

Statistics:-Quartile([1,2,3,4,5,6,7,8], 1, method= 4); 

First 116 117 118 119 120 121 122 Last Page 118 of 395