Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Individual variables can be cleared with unassign.

This may not be the most efficient way, but I think that it is robust and that it handles all the special cases.

power:= (term,x)-> `if`(term=0, undefined, expand(diff(term,x)*x/term));

 

Use piecewise:

f:= t-> piecewise(t < 10, 1-t, t):

f(t);

You have not defined the function for t <= 0 or t = 10. The above will of course apply the upper branch 1-t to t <= 0 and the lower branch to t = 10.

Try this, if you haven't already:

for T from 0 to 15 by 0.1 do
    
your script
end do;

If that doesn't work, then you'll need to post your code.

Yes. The default domain of computation in Maple is the complex numbers; you do not need to make any special declaration.

The complex unit---the square root of -1---is by default represented in Maple by capital I. This can be changed if needed.

The command evalc attempts to break an expression into its real and imaginary parts assuming that any variables in the expression represent real numbers, unless the variables are explicitly declared otherwise. Example:

expr:= exp(x+I*y);

evalc(expr);

evalc(expr) assuming y::complex;

Note that the assumptions that x and y are real are only active during the execution of the evalc command.

The commands Re and Im extract the real and imaginary parts, respectively, of an expression without making any assumptions. They are often used in combination with evalc. Example:

Im(expr);

evalc(Im(expr));

 

 

 

 

 

First, I factored out the constant 2*gamma*cos(psi)*cos(theta). Doing this does not affect Maple's ability to do the integral; it just makes the presentation neater. Then I switched the order of integration and added assumptions D > L and L > 0.

j:= (1/(D-r*sin(theta)*sin(phi))-1/(D+r*sin(theta)*sin(phi)))*r^2*sin(phi);

 

int(int(j, phi= 0..Pi), r= 0..L) assuming D > L, L > 0;

Doing it with

PolynomialTools:-CoefficientVector(p, x, termorder= reverse, storage= sparse)

is much more efficient than using the naive method of calling coeff iteratively.

restart:
NaiveCoeffs:= (p::polynom, x::name)->
     map[3](coeff, p, x, [seq(degree(p,x)..0,-1)]):
N:= 2^11:
P:= ['randpoly(x, degree= N)' $ N]:
time(map(NaiveCoeffs, P, x));

     2.218

time(map(PolynomialTools:-CoefficientVector, P, x, termorder= reverse, storage= sparse));

     0.109

 

This is a DAE system because the EQ3 has no derivatives. Since your previous question had a similar system, which was stiff, I assumed this one was stiff. So I used the stiff DAE solver method= rosenbrock_dae. This produced good, quick results.

Sol:= dsolve(
     {EQ||(1..5), seq(q||k(0)=0, k= {1,2,4,5}), D(q1)(0)=0, D(q2)(0)=0},
     numeric,
     method= rosenbrock_dae
):
plots:-odeplot(Sol, [seq([t,q||k(t)], k= 1..5)], t= 0..0.1);

You can use Maple's plot command to generate the Matrix that you export. This seems useful because you are exporting the Matrix for the purpose of plotting. Maple's plot will automatically choose sufficient intermediate points to make a good plot. Usually it will use about 200 points, but you can adjust that to whatever number you want.

P:= plot(x^2, x= 0..3):
ExportMatrix(
     "C:/Users/Carl/desktop/Filename.txt", op([1,1], P),
     target= delimited, delimiter= " "
);

The code op([1,1], P) is what extracts the data matrix from the plot.

I am not sure what you mean by indenting the negative numbers. If the below is not it, let me know.

S:= map(x-> sprintf("%a", lhs(x)), v1):
S:= map(StringTools:-PadRight, S, max(length~(S))):
seq(printf("%s = %3.3f\n", S[k], rhs(v1[k])), k= 1..numelems(v1));

eta[p2]   = 0.260
eta[p3]   = 0.113
eta[p4]   = -0.013
eta[p5]   = 0.215
eta[p6]   = -0.189
eta[phi2] = 0.020
eta[phi3] = 0.063
eta[phi4] = -0.014
eta[phi5] = -0.414
eta[phi6] = 0.067
mu[p]     = 0.466
mu[phi]   = -0.169
tau[p3]   = 0.000
tau[p4]   = 0.000
w[1]      = 0.023
w[2]      = -0.447
w[3]      = -0.110
w[4]      = 0.035
w[5]      = 0.445

Do you want to create a single 3x3 matrix each element of which is a 3x3 matrix? Or do you want to create a single 9x9 matrix each 3x3 block of which is one of your original matrices?

The first thing is done like this:

A:= Matrix(3, 3, (i,j)-> LinearAlgebra:-RandomMatrix(3,3));

Using those as the starting 9 matrices, the second thing is done like this:

B:= <seq(`<|>`(seq(A[i,j], j= 1..3)), i= 1..3)>;

 

I will describe the way that works for me, which is not the only way, it's just the way that I know.

Pull down the Tools menu and select Options. Go to the second tab, Display. The first item is "Input display". Its value should be "Maple Notation". Change it if it isn't. Now go to the third tab, Interface. The fourth item is "Default format for new worksheets". The value should be "Worksheet". Change it if it isn't. At the bottom of the window, click Apply Globally.

Now open a new worksheet by typing Ctrl-N. In the "Select Math Engine" dialog, select the first item "New". Now look at your toolbar. Do you see in the picture that you inserted in your Question where in the lowest toolbar the leftmost item is a pull-down labelled "P Normal"? In your new worksheet, that should be "C Maple Input". Change it (and let me know!) if it isn't.

Now paste your code to the position that your cursor is now in. If you press Enter, the code should execute. Please let me know how it goes.

From now on, all your worksheets should open being ready to except Maple Input.

expr:= x^2 + x + 2:
subs(x= x+1
, expr);

I'd recommend that you not copy output to input by cut-and-paste. In addition to the problems that you've already noticed, it tends to make your code less readable, less modifiable, and less able to be executed by someone else.

#Works like 'select' except that it returns a list of the indices.
SelectIndices:= proc(f::appliable, L::{list,set,Vector})
local k;
     [seq(`if`(f(L[k], _rest), k, [][]),  k= 1..numelems(L))]
end proc:

     
a:= Vector([2,3,4,5]):
SelectIndices(`>=`, a, 3);

Edit: Answer updated to use _rest based on the Reply by Joe Riel below.

First 296 297 298 299 300 301 302 Last Page 298 of 395