Maple 2020 Questions and Posts

These are Posts and Questions associated with the product, Maple 2020

I have four equations,

y = 1/x, y=3, y=1, x=0

restart;

P1 := plots:-implicitplot(y=1/x, x=-1..2, y=0..4, color=black, scaling=constrained):
P2 := plots:-implicitplot(y=3,   x=-1..2, y=0..4, color=black):
P3 := plots:-implicitplot(y=1,   x=-1..2, y=0..4, color=black):

plots:-display([P1,P2,P3]);

How do I fill the area between the first three equations and the y axis (x=0)?

Is it possible to do this with plottools:-transform?

I know this has to do with name scoping issue. But I do not see how to fix it now.

Calling J,Q:=LinearAlgebra:-JordanForm(A,output=['J','Q']); works in global, but not inside a proc.

What is the correct way to use this inside a proc?


 

restart;
A:=Matrix([[1,2],[3,4]]);
J,Q:=LinearAlgebra:-JordanForm(A,output=['J','Q']);

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 2, (2, 1) = 3, (2, 2) = 4})

Matrix(%id = 18446745500542083790), Matrix(%id = 18446745500542076678)

restart;
foo:=proc(A::Matrix)
local J,Q;
J,Q:=LinearAlgebra:-JordanForm(A,output=['J','Q']);
end proc;
A:=Matrix([[1,2],[3,4]]);
foo(A);

foo := proc (A::Matrix) local J, Q; J, Q := LinearAlgebra:-JordanForm(A, output = ['J', 'Q']) end proc

Matrix(%id = 18446745500542658910)

Error, (in foo) invalid input: LinearAlgebra:-JordanForm expects value for keyword parameter output to be of type {list(identical(J, Q)), identical(J, Q)}, but received [J, Q]

 


 

Download jordan_issue.mw

Hi

I am on my way to construct a matrix for centripetal and Coriolis forces for a robot arm. However this requeers that I use a sum where the matrix index is the sumations index.

So I started testing things out before I constructed the full expresion, this is what I did.

According to the error page, this is du to that k in M[1,k] is an bad index, however in the sum this would be k=1 och k=2 whitch are vallid.

Do anybody know a way around this problem or can tell me what I did wrong.

 

Many thanks

Eric Ragnarsson

plots:-contourplot(16.70196911*2^(1/2)*((x^2 + 0.1*y)/((1 - x)*(3*x^2 + 0.2*y)))^(1/2)/(4.373839156*(x^2 + 0.1*y)/((1 - x)*(3*x^2 + 0.2*y)) + 1)^(1/2), x = 0.001 .. 1, y = 0.001 .. 1, contours = 20, thickness = 0, coloring = ["blue", "yellow"], axes = "boxed", filledregions = true)

I have tried many times, such as adding legendstyle = [position=correct],legend = true command, but it always report errors.

Can anyone help me solve this problem? Thank you.

Hi,

I'm trying to make Maple reduce an extensively simple complex equation, something so simple anybody with basic knowledge of complex numbers would take about 2 mins to solve manually.

Yet, I can't seem to get Maple to do it, which is disappointing. I can only hope the issue is on my side (I would be glad to be the one in the wrong).

 

example.mw

 

I expect at the last line a reduction to s^2 + 2*z*omega__n * s + omega__n^2

I tried different combinations of simplification functions without success. Simplify doesn't work much better.

 

Basically looking at something like this, but on Maple (this comes from Maxima), if possible *WITHOUT* the need for assume() on any scale (just like Maxima and Mathematica) :

Thanks!

I remember seeing sometime ago an option called something like "fraction free" in LinearAlgebra. But may be I was looking at something else or different package. I can't remember now. I searched the help pages now and googled and can't find it.

In Maple, when asking for eigenvectors of matrix, I'd like the vectors to come out fraction free, like with Mathematica.

It is ofcourse easy to write code to post process this and remove the fractions.

But before I do this, I thought to ask. Here is an example

restart;
A:=Matrix([[48,-30,-14,1],[65,-41,-19,0],[17,-10,-5,3],[-35,22,10,0]]);
(e,v):=LinearAlgebra:-Eigenvectors(A);

In Mathematica:

Anyone knows if such option exists somewhere?

Maple 2020.1

Heck Example 15.5 must have worked for an old version of maple.

restart;
## plot two functions and color the region between
sine :=   plot(sin(x), x=0..4*Pi, color=black,thickness=3):
s    :=   plot(sin(x), x=0..4*Pi, color=red, filled=true):
cosine := plot(cos(x), x=0..4*Pi, color=black,thickness=3):
c      := plot(cos(x), x=0..4*Pi, color=red, filled=true):
f := x -> if cos(x)>0 and sin(x)>0 then
              min(cos(x),sin(x))
          elif cos(x)<0 and sin(x)<0 then
              max(cos(x),sin(x))
          else 0
          end if;
b := plot(f(x), x=0..4*Pi, filled=true, color=green):

display([sine, cosine, b, s, c]):

Gives the error.

Error, (in f) cannot determine if this expression is true or false: 0 < cos(x)
and 0 < sin(x)

I tried verify(cos(x),0,less_than) and verify(sin(x),0,less_than), etc., but that makes f(x) always return 0.

f := sin(x);
g := cos(x);
plottools:-transform(unapply([x,y+g],x,y))(plot(f-g,x=0 .. 4*Pi,filled=true));
Works, but, I can not remember how that works.

Is it possible to use if in maple 2020.

In this example, PDEtools:-Solve throws an error, while solve returns empty solution.

Why the different behavior? Should PDEtools:-Solve also return empty solution like solve?

I noticed this, when I changed my code from using solve to using PDEtools:-Solve

restart;
eq:=[ eta1+2*eta2 = 0, eta1+2*eta2 = a1+a3, eta2 = a2+2*a3];
PDEtools:-Solve(eq,[a1, a2, a3]);


solve(eq,[a1, a2, a3])

interface(version)
Standard Worksheet Interface, Maple 2020.1, Windows 10, July 30 

   2020 Build ID 1482634


Physics:-Version()

The "Physics Updates" version in the MapleCloud is 832 and is 

   the same as the version installed in this computer, created 

   2020, October 3, 5:34 hours Pacific Time.


Maple 2020.1 

DataFrames: An example from the 2020 U.S. Presidential election

(Or why DataFrames are more powerful and readable than spreadsheets.)

 

In this example of working with DataFrames, the goal is to use a spreadsheet from a website, which contains polling data, to estimate the probability each of the two candidates from the major parties will win the US Presidential election in November.  I first tried doing the calculations with a spreadsheet, but I discovered DataFrames was far more powerful. Warning: This worksheet uses live data. Hence the outcome at the end of the worksheet is likely to change daily. A more extensive example with even more common DataFrame operations should be available soon.

 

How the US Presidential election works - highly simplified version: In the US there are only two parties for which their candidate could win the election:  the Democratic party and Republican party. The Republican party is often referred to as the "Grand Old Party", or GOP. Each state executes its own election. The candidate who receives the most votes wins the states "electoral votes" (EV). The number of the electoral votes for each state is essentially proportional to the population of the state. A candidate who receives a total of 270 or more EVs out of 538, is declared the president of the US for the next term, which starts January 20 of 2021.

 

Creating DataFrame from web based data:

First I download the data from the website. It is a CSV spreadsheet.

 

restart; interface(displayprecision = 3); interface(rtablesize = [6, 8]); web_data := Import("https://www.electoral-vote.com/evp2020/Pres/pres_polls.csv")

_m2211970420352

Each row contains information about a poll conducted in one of the states.  The first poll starts on row 2, hence the number of polls are:

Npolls := upperbound(web_data, 1)-1

572

Now I want to create a new DataFrame containing only the most useful information. In web_data, many are the columns are not important. However I do want to keep the column label names from those columns I wish to retain.

 

web_data_cols := [1, 3, 4, 5, 6]; column_labels := convert(web_data[1, web_data_cols], list)

["Day", "State", "EV", "Dem", "GOP"]

 

Because  the first poll in web_data is labeled 2, I would like to relabel all the polls starting from 1

row_labels := [seq(1 .. Npolls)]

 

Creating a DataFrame from a Matrix or another DataFrame:  (with row labels and column labels)

 

Now I can build the DataFrame that I will be working with:

 

poll_data := DataFrame(web_data[2 .. (), web_data_cols], 'columns' = column_labels, 'rows' = row_labels)

_m2211956910784

What each column means

* "Day" - day of the year in 2020 when the poll within the state was halfway completed. The larger the value, the more recent the poll.

* "State" - the state in the US where the poll was conducted. The candidate that receives the most votes "wins the state".

* "EV" - the number of electoral votes given to the candidate who receives the most votes within the state.

* "Dem" - the percentage of people who said they are going to vote for the candidate from the Democratic party.

* "GOP" - the percentage of people who said they are going to vote for the candidate from the Republican party.

Sorting:

By using the sort function, using the `>` operator, I can see which polls are the more recent. (If you run the worksheet yourself, the outcome will change as more polls are added to the website spreadsheet.)

poll_data := sort(poll_data, "Day", `>`)

_m2211960016288

 

Selecting Unique entries - by column values:

For the my simple analysis, I will use only the most recent poll, one from each state. Hence, using AreUnique, I can pull the first row that matches a state name. This new DataFrame called states.

 

states := poll_data[AreUnique(poll_data["State"])]

_m2211969565344

(Note, one of the "states" is the District of Columbia, D.C., which is why there are 51 rows.)

 

Removing a column: (and relabeling rows)

This next example isn't necessary, but shows some of the cool features of DataFrames.

 

Since there is only 1 entry per state, I'm going to remove the "State" column and relabel all the rows with the state names

state_names := convert(states["State"], list); states := DataFrame(Remove(states, "State"), 'rows' = state_names)

2

_m2211957755840

 

Indexing by row labels:


This allow me to to display information by individual states. What is the data for California, Maine and Alaska?

states[["California", "Maine", "Alaska"], () .. ()]

_m2211977321984

 

Mathematics with multiple-columns:

 

My preference is to work with fractions, rather than percentages. Hence I want all the values in the "Dem" and "GOP" to be divided by 100 (or multiplied by 1/100).  Treating each column like a vector, the multiplication is performed individually on each cell. This is what the tilda, "~", symbol performs.

states[["Dem", "GOP"]] := `~`[`*`](states[["Dem", "GOP"]], 1/100.); states

_m2211957755840

 

Mathematics: using a function to calculate a column

 

For the next action, I want to use the power of the Statistics package to create a "probability of winning the state" function.

 

For simplicity, I will assume the outcome of the voting in a state is purely random, but is conditional to popularity of each candidate as measured by the polls. I'll assume the likelihood of an outcome follows a normal (Gaussian) distribution with the peak being at point where the difference of the polling of the two candidates is zero. (Note, other than 2016, where there was an unusually larger percentage of undecided voters on election day, this simple model is reasonable accurate. For example, in 2012, of the states which appeared to be the "closest", the winner over-performed his polling in half of them, and under-performed in the other half with a mean difference of nearly zero.)  From previous elections, the standard deviation of differences between polling values and the actual outcome is at most 0.05, however, it does increase with the fraction of undecided voters.

 

To mathematically model this situation, I have chosen to use the "Cumulative Density Function" CDF in the Statistics package. It will calculate the probability that a candidate polling with fraction f1 wins the election if the other candidate is polling with fraction f2.  The variable u is the fraction of undecided voters. It is included in the calculation to increase the spread of the possible outcomes.

 

win_prob := Statistics:-CDF(Statistics:-RandomVariable(Normal(0., 0.5e-1+(1/4)*u)), f1-f2)

1/2+(1/2)*erf((1/2)*(f1-f2)*2^(1/2)/(0.5e-1+(1/4)*u))

 

Converting this expression into a function using the worst named function in Maple, unapply:

win_prob_f := unapply(evalf(win_prob), [f1, f2, u])

proc (f1, f2, u) options operator, arrow; .5000000000+.5000000000*erf(.7071067810*(f1-1.*f2)/(0.5e-1+.2500000000*u)) end proc

 

Now I can calculate a DataFrames column of the "win probability", in this case, for the candidate from the Democratic platy. By apply the function, individually, using the columns "Dem" and "GOP", I produce:

dem_win_prob := `~`[win_prob_f](states["Dem"], states["GOP"], `~`[`-`](1, `~`[`+`](states["Dem"], states["GOP"])))

_m2212010910496

Appending a column:

 

I can add this column to the end of the states with the label "DemWinProb":

 

states := Append(states, dem_win_prob, label = "DemWinProb")

_m2212009017568

 

Mathematics of adding the entries of a column:

 

How many electoral votes are available? add them up.

Total_EV := add(states["EV"])

538

 

While the number of EV a candidate wins is discrete, I can use the "win probability" from each state to estimate the total number of EV each of the candidates might win. This means adding up number of EV in each state times, individually, the probability of winning that state:

Dem_EV := round(add(`~`[`*`](states["EV"], states["DemWinProb"])))

354

Currently, the candidate from the Democratic party is likely to win more then 300 electoral vtes.

 

What about for the candidate from the Republican / "GOP" party?

gop_win_prob := `~`[win_prob_f](states["GOP"], states["Dem"], `~`[`-`](1, `~`[`+`](states["Dem"], states["GOP"]))); GOP_EV := round(add(`~`[`*`](states["EV"], gop_win_prob)))

184

Summing the two EV values, we obtain the total number of electoral votes.

Dem_EV+GOP_EV

538

  NULL

 

Download DataFrames_Example.mw

Hello

Just started out with maple. 

I entered a function that looks like this, to find the volume of a sphere: V := (4*Pi(d/2)^3)/3

then I use the eval command like this: eval(V, d = 6.35*mm)

and I get this:(4*Pi(3.175000000*mm)^3)/3

Anything I tried, maple doesn't want to spit out one number! I just need what that is equal to, I don't need an expression with Pi. Spent over two hours trying to figure it out, watching videos etc but no luck! hoping that someone can help me with this!

Charging a capacitor with a DC is well known and interaction with a sinusoidal signal is known to perfection.

The mathematical solutions behind an arbitrary waveform V1(t) is hard or impossible? to find .

To simplify, the arbitrary wave can be expressed with a 2-d degree polynom. This gives a fairly simple

expression with an integral. The problem however is that V2(t) - the capacitor voltage - appears on both sides and maple seems unable to resolv this into a symbolic expression.

If this can be solved it would be great ! The solution should be of the symbolic form V2(a,b,c,V2start,t1,t2,RC) and give the answer what voltage the capacitor V2 would reach arter charging between t1 and t2  with a V1(t) that is changing during charge.

How do I plot the complex function |z+1||z-1|=1 in Maple? I know there is complexplot but don't quite understand how to use it.

Why Maple gives different looking solution when calling  

dsolve(sys);

vs.

dsolve(sys,deps);

? Both solution are actually correct. But look different.  Here is an example

restart;
sys:=[
diff(x(t),t) = 2*x(t)-z(t), 
diff(y(t),t) = 2*y(t)+z(t), 
diff(z(t),t)=2*z(t),
diff(w(t),t)=-z(t)+2*w(t)];
deps:=[x(t),y(t),z(t),w(t)];

dsolve(sys);

dsolve(sys,deps);

Notice the difference:

In first case, the x(t) and y(t) solutions have 2 constants of integrations, and in the second case, they have 3 constants of integration.

If we solve this using the matrix exponential method, the solution comes out to match the first one:

A:=Matrix([[2,0,-1,0],[0,2,1,0],[0,0,2,0],[0,0,-1,2]]):
sol:=Vector([x(t),y(t),z(t),w(t)])=LinearAlgebra:-MatrixExponential(A,t).Vector([_C1,_C2,_C3,_C4]);
simplify(sol)

Again, both solution verify to 0, using odetest, and I assume now it is correct (have no reason to think odetest is not correct).

But I'd like to understand more why when passing the unknowns to dsolve, the solution comes out different looking (3 constants of integrations, vs. two in this case). Should the solution be the same looking in both cases? 

This came out, since I thought my solution was wrong, since it did not look like Maple's. 

 

Maple 2020.1

 

In a recent question, the solution involved [...]::[list$3].

H:= proc(n, x, y)
    if n=0 then y+1
    elif n=1 and y=0 then x
    elif n=2 and y=0 then 0
    elif y=0 then 1
    elif not [n,x,y]::[nonnegint$3] then 
        'procname'(n-1, x, 'procname'(n, x, y-1))
    else
        thisproc(n-1, x, thisproc(n, x, y-1))
    fi
end proc

Where is  the  form [...]::[list$3] documented?

 

 

Hi all,

There is issue with saving big numbers to txt file on WIndows

Please look at the file:

txt_issue.mw

Function save just cutting a big number.

Thank you.

First 33 34 35 36 37 38 39 Last Page 35 of 55