dharr

Dr. David Harrington

7119 Reputation

21 Badges

20 years, 151 days
University of Victoria
Professor or university staff
Victoria, British Columbia, Canada

Social Networks and Content at Maplesoft.com

Maple Application Center
I am a retired professor of chemistry at the University of Victoria, BC, Canada. My research areas are electrochemistry and surface science. I have been a user of Maple since about 1990.

MaplePrimes Activity


These are replies submitted by dharr

@HaHu This is hard to diagnose without the worksheet, which you can upload with the big green up-arrow.

@wswain It's a good point. Using op and elementwise operators (the ~ thing) tends to make Maple unreadable for those who don't use it much. So I would use RowDimension rather than its op equivalent. There are also efficient ways to do things (like map) that avoid using loops. But you can write more "fortranlike" code with loops. You could for example fill a matrix with nested do loops. There is perhaps a tendency on Mapleprimes to suggest short and clever but less readable answers.

(And to answer your question on dynamic Arrays/Vectors/Matrices, you can dynamically extend these by using programmer indices - see ?Indexing Arrays)

@wswain  This might answer some of your questions about @tomleslie 's response.
 

restart;

with(LinearAlgebra):

A:=Matrix([[1,2],[3,4],[5,6]]); #list of lists Matrix construction

_rtable[18446744944491233278]

Matrix([A[1,..],A[2,..],A[3,..]]); #three rows are just next to each other

_rtable[18446744944491236158]

Matrix([A[1,..],A[2,..],A[3,..]],scan=columns); #list Matrix construction - rows below

_rtable[18446744944805409126]

Dimensions(A);
op(1,A); # same thing

3, 2

3, 2

RowDimension(A);
op([1,1],A); # same thing - first op of op(1,A);

3

3

n:=2;
`if`(n=2,A[2,..],"smile");
`if`(n=2,A[2,..],NULL);
B:=Matrix([A[1,..],`if`(n=2,A[2,..],NULL)],scan=columns);

n := 2

_rtable[18446744944805411526]

_rtable[18446744944805404910]

Matrix(%id = 18446744944805405870)

n:=26;
`if`(n=2,A[2,..],"smile");
`if`(n=2,A[2,..],NULL); # nothing so no output
B:=Matrix([A[1,..],`if`(n=2,A[2,..],NULL)],scan=columns);

n := 26

"smile"

Matrix(%id = 18446744944805407670)

f:=x->x^2; #squaring function (procedure)

proc (x) options operator, arrow; x^2 end proc

f(3);

9

map(f,A); #apply to every entry
f~(A);    #same thing

_rtable[18446744944805402254]

Matrix(%id = 18446744944805403574)

 


 

Download MatrixNotes.mw

@Carl Love Thanks. I was just being cautious. My information is probably out of date, but I had a recollection that in older versions there were some minor differences, perhaps in the maximum setting of Digits. But I don't see any differences mentioned on the website.

@Melvin Brown Looks like you split it into real and imaginary parts. Probably a good idea for a numerical solution, but for an analytical solution, a single complex  equation will probably work better. I'm guessing with this time dependence it's separable into a function of time multiplied by a function of (x,y). I would also probably look for a general solution first - if you can find that then add the BCs/ICs later.

Good luck.

My reading of your problem is that you don't have a way of entering inactive 2-D math, only changing active to inactive by shift-F5. In Maple 2017 (I don't have 2019), entering inactive 2-D math can be done directly with shift-F5, though perhaps you know this already ( @acer 's q1.)

 

@acer Thanks - homedir is the same on Maple and Maple Player (as expected), so I can work relative to there as a workaround.

I usually put my worksheet in the directory with the data files I want to analyze, then open files relative to worksheetdir, which for this case is the same as currentdir. This means the worksheet doesn't need to be modified if I send it to to someone else who operates the same way. In an interactive application I can use a combo box to list the files in worksheetdir and the user can choose one, not having to change or choose a directory.

@ALIKHADEMI to make variable "a" a Vector, use a:=Vector([seq(1..10,0.5)]);

The rest of the code is the same. I don't understand the rest of your question. To better understand elementwise operators, take a look at the help page for elementwise.

@pu397 You'll have to use Eq 27 or the like instead of Eq. (12). I didn't spend much time trying to understand the method, just suggested the general strategy for using Maple. I'm currently travelling, so don't have much time, so suggest you make a first attempt, and pehaps someone here can help correct it for you.

@Carl Love Thanks for the tip.

@acer @nm This is often (usually) a hidden file.

@acer I like to let the OP do some of the work :-). My variation would have been to solve some eqns:
 

Gc := (s^2*t^2+2*s*t*x+1)*(-b*s+1)/(k*(-b*s+1)*s*(t*c+b));

(s^2*t^2+2*s*t*x+1)/(k*s*(c*t+b))

Gc2:=expand(convert(Gc,parfrac,s));

t^2*s/(k*(c*t+b))+2*t*x/(k*(c*t+b))+1/(k*s*(c*t+b))

eqns:={A=coeff(Gc2,s,0),A*C=coeff(Gc2,s,1),A/B=coeff(Gc2,s,-1)};

{A = 2*t*x/(k*(c*t+b)), A/B = 1/(k*(c*t+b)), A*C = t^2/(k*(c*t+b))}

ABC:=solve(eqns,{A,B,C});

{A = 2*t*x/(k*(c*t+b)), B = 2*t*x, C = (1/2)*t/x}

Gc3:=A*(1+1/(B*s)+C*s);
simplify(eval(Gc3,ABC)-Gc);

A*(1+1/(B*s)+C*s)

0

 


 

Download parfrac.mw

@AntoineR Looks like you may have used 2-D input. From your original post, I added multiplications after k, the last s and between t and c. If the first two are omitted, Maple thinks that they are functions f() and s() and so does not think that you have a rational function. In 2-D input use a space or * to distinguish multiplication from functions.

@dharr and to get the coefficients you can use

coeff(Gc2,s,0); coeff(Gc2,s,1); coeff(Gc2,s,-1);

(can't seem to edit my post).

@Joe Riel  Of course I agree the help page is confusing. At one point, it says that all entries of an rtable are "scanned" (as opposed to all opererands), and later that for sparse rtables only the nonzero ones are "scanned", so they can't both be correct.

But I expect (1) any mathematical operation on an rtable to give the same result, whether sparse of not, and (2) some algorithmic efficiencies  may be be applied if it is sparse.

So I think the first point (and the first usage of scan in terms of all entries) means I expect to see seq return the number of elements of the rectangular size. In the case of mul (which has the same strange wording about "scan"), mul(V) returns 0, (as I expect) - it involves the same result as if non sparse, and must involve more that just the stored entries.

I took the second usage of scan (that for sparse rtables only the non-zero entries are scanned), to be associated with the second point, that somehow seq uses a more efficient algorithm, and can be faster because it doesn't attempt to access the non-zero entries. 

But perhaps this is just me being optimistic that there is some resonable meaning behind the second usage (that @vv pointed to as strange)...

 

First 60 61 62 63 64 65 66 Last Page 62 of 73