Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Why does no substitution work on functions with s(n+1,t) (see eqns (2-8))? Also (∂)/(∂ (sigma2*t))=1/(sigma2)(∂)/(∂ t), how can I do it on Maple?shift.mw

I am trying to load the third-party package 'CPC Program Library (qub.ac.uk)' by following the instructions as in 'how to install wkptest? - MaplePrimes'. But encounter with Errors: '

Error, `:` unexpected
with(wkptest);
Error, invalid input: with expects its 1st argument, pname, to be of type {`module`, package}, but received wkptest

restart:

sourcefolder:=cat(kernelopts('C:\Users\ahmed\Downloads\adty_v1_0'),"/wkptest");
installfolder:=cat(kernelopts('homedir'),"/maple/toolbox/wkptest/lib");
FileTools:-MakeDirectory(installfolder, 'recurse'=true);
libraryfile:=cat(installfolder,"/wkptest.mla");
try
  FileTools:-Remove(libraryfile);
catch:
end try:
LibraryTools:-Create(libraryfile);
libname:=libraryfile,libname;
read cat(sourcefolder,"/wkptest_cpc");

Error, `:` unexpected

 

with(wkptest);

Error, invalid input: with expects its 1st argument, pname, to be of type {`module`, package}, but received wkptest

 
 

 

Download exam_wkptest1.mws

When I calculate the difference between two dates with the same day using the DateDifference Calendar function, I don't get an integer number of months, but results with extra days, hours, minutes, seconds and milliseconds. How can I calulate the actual number of months?

I appreciate any help.

restart

with(Calendar)

d1 := Date(2024, 1, 5, 0, 0, 0)

_m4674925856

(1)

d2 := Date(2024, 5, 5, 0, 0, 0)

_m4881744064

(2)

DateDifference(d1, d2, 'units' = 'mixed')

4*Units:-Unit(mo)+2*Units:-Unit(d)+20*Units:-Unit(h)+3*Units:-Unit(min)+48*Units:-Unit(s)+800*Units:-Unit(ms)

(3)

NULL

NULL

 

NULL

Download DateDifference.mw

How can I calculate the integral of Legendre function P(n,theta) ?

int(cos(theta)*P(n,theta),theta=0..pi) ;

I never used Maple's StringTools:-RegSubs before.

I have a Latex string generated by Maple that has this form

"......    \\textrm{ ......   }  .... "

Where the dots mean anything, including space characters.  I need to change the part of the string  "\\textrm{ ...... }" to this

"......  \\begin{minipage}{\\linewidth}\\textrm{  ......   }\\end{minipage}  .... "

It is easy to change the opening part. Here is an example

s:="A& B& \\textrm{The fundamental matrix has } &C ";
s:=StringTools:-SubstituteAll(s,"\\textrm{","\\begin{minipage}{\\linewidth}\\textrm{");

Gives

The problem is how to replace the closing "}"  with "}\\end{minipage}".   I can't just replace "}" with "}\\end{minipage}" using SubstituteAll because I need to only change the "}" that closes the corresponding "\\textrm{" and not any other "}" that could be in the string.

So I need to use pattern matching or regular expression substitutions. The examples in help are not easy to understand.

 

Basically I need regular expression that matches 

                        "\\textrm{ WILDCARD * }" 

and change it to 

                        "\\begin{minipage}{\\linewidth}\\textrm{ WILDCARD * }\\end{minipage}" 

Any one know how to use Maple's egular expression to do this substitution using the above example?

Maple 2024 on windows 10.

Update

Thanks for the replies. I ended up writing small function that simply scan the string and do the replacement. 

Hi,

I want to analyze a quartic equation: rho-analysis.mw. I am interested in positive roots, which I need expressed in explicit/closed form.

I include four questions in the script.

Thanks!

EDIT (since my question was originally tagged as incomplete and even duplicate):
Above all I am trying to understand:

  1. Why implicitplot3d returns a unique strictly positive root for all rho and Gamma but plot() of the quartic evaluated for a specific pair of value returns three positive roots?
  2. rho is a correlation coefficient, thus bounded in (-1,+1): how to adjust the precision of the slider in Explore() so that I can play around with multiple rho values within said range?

Can this be better done in Maple ? , see worksheet.

Printlevel can be used to understand how Maple processes input. In some cases printlevel has to be increased to high values which produces an ennormeous amount of output.

In case a particular procedure has been identified for detailed analysis it would be desirable only for this procedure to set a printlevel. Kind of a local printlevel.

Does something like this or other ways exist?

trace as I understand it only traces the procedure given as argument but not levels "below".

In this exercise, we are going back to the simple SIR model, without births or deaths, to look at the effect of vaccination. The aim of this activity is to represent vaccination in a very simple way - we are assuming it already happened before we run our model! By changing the initial conditions, we can prepare the population so that it has received a certain coverage of vaccination.

We are starting with the transmission and recovery parameters b = 0.4 days-1 and  c=0.1 days-1. To incorporate immunity from vaccination in the model, we assume that a proportion p of the total population starts in the recovered compartment, representing the vaccine coverage and assuming the vaccine is perfectly effective. Again, we assume the epidemic starts with a single infected case introduced into the population.​
We are going to model this scenario for a duration of 2 years, assuming that the vaccine coverage is 50%, and plot the prevalence in each compartment over time.

I have used the following code to solve this problem but I face difficulties when I am trying to define and plot the effective reproduction number.

Any suggestions? Thank you in advance!
with(Physics, diff);
with(LinearAlgebra);

with(plots);
with(DEtools);

b := 0.4;
c := 0.1;
n := 10^6;
p := 0.5;
deS := diff(S(t), t) = -b*S(t)*I0(t);
deI := diff(I0(t), t) = b*S(t)*I0(t) - c*I0(t);
deR := diff(R(t), t) = c*I0(t);

F := dsolve([deS, deI, deR, S(0) = 1 - p, I0(0) = 1/n, R(0) = p], [S(t), I0(t), R(t)], numeric, method = rkf45, maxfun = 100000)

odeplot(F, [[t, S(t)], [t, I0(t)], [t, R(t)]], t = 0 .. 730, colour = [blue, red, green], legend = ["S(t)", "I0(t)", "R(t)"], labels = ["Time (days)", "Proportion of Population"], title = "SIR Model with vaccination")


#define the effective reproduction number
Reff := t -> b*1/c*S(t)*1/n;
Reff(100);

I have been trying to solve the following diffusion equations

  diff(u(z, t), t) = D*diff(u(z, t), z, z) + A*z*exp(lambda*z)

my boundary canditions are

  u(0,t)=0,D(u)(H,t)=0,u(initinity,t)=0

I have followed the examples on tte link below, but I am unable to get the solution when I write the boundary conditions. It there anything I am doing wrongly? I would be most grateful if an email can be sent to me with with the solution that I can download fram an attachment

Thanks

https://www*mapleprimes*com/posts/209970-Exact-Solutions-For-PDE-And-Boundary--Initial-Conditions-2018

SI_MODEL.mw
I have tried the following code to simulate the following SI Model. But when I run it, it gives me several mistakes and most importantly does not calculate the Jacobian Matrix and the eigenvalues. 

Any help would be deeply appreciated


Many of the most interesting dynamics in nature have to do with interactions between organisms. These interactions are often subtle, indirect, and difficult to detect. Interactions in which one organism consumes all or part of another. This includes predator-prey, herbivore-plant, and parasite-host interactions. These linkages are the prime movers of energy through food chains. They are an important factor in the ecology of populations, determining the mortality of prey and the birth of new predators.

Mathematical models and logic suggest that a coupled system of predator and prey should cycle: predators increase when prey is abundant, prey are driven to low numbers by predation, the predators decline, and the prey recover, ad infinitum. One such model that simulates predator-prey interactions is the Lotka - Volterra Model.

 


We will discuss a behavior of 2 D - subsystems: SI - model.


SI Model (without predator)

 

We will study a mathematical model that appears in eco - eco-epidemiology.


The SI model describes the interactions between S-prey with density x and I-prey with density y under the assumption z≡0


Break the population into compartments.

• 

Prey (S)

• 

Infected prey (I)


SI Equations :

(D(x))(t) = r*x(t)-b*x(t)^2-c*x(t)*y(t)-beta*x(t)*y[t]/(a+x(t))

(D(y))(t) = -mu*y(t)+beta*x(t)*y(t)/(a+x(t))

– 

 r stands for the intrinsic growth rate of S-prey.

– 

b defines the intra-class competition in S-prey.

– 

c characterizes the inter-class competition between S-prey and I-prey.

– 

μ stands for the mortality of the I-prey

– 

β considered as the bifurcation parameter.

• 

Note: The dynamics of the system depend on parameter β

 

Modeling with Differential Equations

 

• 

We will fix the parameters in the study to have the following values r = 1, b = 1, c = 1/100, μ = 4/10, a=1/2.75.

• 

The initial values will be x(0)=0.2, y(0)=0.05


As mentioned above the dynamics of the system depend on parameter β. So we will consider two cases when β=0.75 and β=1


We will solve the system for the above values of parameters and initial conditions and for a time interval [0,200] , then we will create its plots

 

Case 1

  restart

beta := .75; r := 1; b := 1; c := 1/100; mu := 4*(1/10); a := 1/2.75; f := r*x(t)-b*x(t)^2-c*x(t)*y(t)-(3/4)*x(t)*y(t)/(a+x(t)); g := -mu*y(t)+(3/4)*x(t)*y(t)/(a+x(t)); deq1 := diff(x(t), t) = f; deq2 := diff(y(t), t) = g; equilibrio := solve({f = 0, g = 0}, {x(t), y(t)}); jacobian := simplify(Matrix(2, 2, [[diff(f, x(t)), diff(f, y(t))], [diff(g, x(t)), diff(g, y(t))]])); A := simplify(eval(jacobian, equilibrio[1])); B := simplify(eval(jacobian, equilibrio[2])); Q := simplify(eval(jacobian, equilibrio[3])); eigen1 := Eigenvalues(A); eigen2 := Eigenvalues(B); eigen3 := Eigenvalues(Q); soln := dsolve({deq1, deq2, x(0) = .2, y(0) = 0.5e-1}, numeric, output = listprocedure); plots:-display(plots:-odeplot(soln, [t, x(t)], 0 .. 200, color = blue, legend = ["x(t)"]), plots:-odeplot(soln, [t, y(t)], 0 .. 200, color = red, legend = ["y(t)"]), labels = ["t", "Population"], title = "Population Dynamics")

 

NULL

 

 

Case 2

restart``

beta := 1; r := 1; b := 1; c := 1/100; Mu := 4*(1/10); a := 1/2.75; f := r*x(t)-b*x(t)^2-c*x(t)*y(t)-x(t)*y(t)/(a+x(t)); g := -Mu*y(t)+x(t)*y(t)/(a+x(t)); deq1 := diff(x(t), t) = f; deq2 := diff(y(t), t) = g; equilibrio := solve({f = 0, g = 0}, {x(t), y(t)}); jacobian := Matrix(2, 2, [[diff(f, x(t)), diff(f, y(t))], [diff(g, x(t)), diff(g, y(t))]], simplify); J_at_equilibrio := [eval(jacobian, equilibrio)]; eigen1 := Eigenvalues(A); eigen2 := Eigenvalues(B); eigen3 := Eigenvalues(Q); soln := dsolve({deq1, deq2, x(0) = .2, y(0) = 0.5e-1}, numeric); plots:-display(plots:-odeplot(soln, [t, x(t)], 0 .. 200, color = blue, legend = ["x(t)"]), plots:-odeplot(soln, [t, y(t)], 0 .. 200, color = red, legend = ["y(t)"]), labels = ["t", "Population"], title = "Population Dynamics with Beta = 1")

 

NULL


 

Download SI_MODEL.mw

 

 

p eriode:=proc(r::rational)""  local a,b,c,f,i,k,l,p,q,s:  s:=couvert(evalf(abs(r)-trunc(r),50),string):  if  s[1]="." then s:=s[2..length(s)] fi:  a:=numer(simplify(r)): b:=denom(simplify(r)):  if  igcd(b,10)=1 then       q:=0:       p:=1:      while (10^(p) mod b)<>1 do  p:=p+1 od:  else      f:=ifactors(b)[2]:      k:=0:l:=0:      for i  ;
to nops(f) do
        if f[i][1]=2 then k:=f[i][2] fi:
        if f[i][1]=5 then l:=f[i][2] fi: 
     od:
   c:=b/(2^k*5^l):
   q:=max(k,l):
   if c=1 then p:=0 else p:=op(2,periode(1/c)) fi:
fi:
[q,p,[seq(parse(s[k]),k=1+q..q+p)]]
end:
Error, improper op or subscript selector
Error, reserved word `fi` unexpected
I don't understand these errors. Thank you.

How can I make if-statement work in my code?
assuming m,n :: integers
Thank you in advance.

restart;

 

x2 := proc(m,n)
  if ((is(m,even) and is(n,odd)) or (is(m,odd)and is(n,even))) then -8*L*m*n/(m+n)^2/Pi^2/(m-n)^2;
  else  0;
  end if;
end poc:

Error, missing operator or `;`

 


Download test2.mw

The uploaded worksheet is intended to be an example of the Equal Incircles Theorem, but the incircles displayed are not equal.

What is wrong in the worksheet and how can the error(s) be corrected?

Equal_Incircles_theorem.mw

5 6 7 8 9 10 11 Last Page 7 of 2114