MaplePrimes Questions

@Carl Love
@acer
Hi. 

This Carl code works

standings_DRAW.mw

Could someone please make my modified code work:

(Case D should be the same as P-Q=0 , when integer score P,Q is entered and P=Q)

standings_SCORE.mw

EDIT: corrected and reuploaded: should have been if P-Q <> 0 rather than P-Q=0. changes in purple.

(ps I don't want a substitution D when P-Q=0)

Dear house 

I am new to maple and will really appreciate some assistance in calculating the disease free , endemic equilibrium states and basic reproduction number for my model.

 

I have been trying for weeks. any asistance will be much appreciated

SCI_HELP.mw

 

Is there a way to get the generalized Fourier series with respect to an arbitrary orthogonal system (instead of just sin, cos, exp, etc.) using the OrthogonalExpansions package or any other way in Maple?

Hello!

Could you help me please...

There are lot's of packages and instructions how to expand function to Fourier Series but in 2006, 2010

Please help...

 

Hello there, 

I wonder if there is any method to eliminate the terms ((6.*10^(-11))*I) in this worksheet. Apparently, they came from the limitation of the numerical precision. 


 

restart;

M2[transform] := <<2/(sqrt(3)*a),-1/(sqrt(3)*a),-1/(sqrt(3)*a)> | <0, -1/a, 1/a>>;

Matrix(3, 2, {(1, 1) = (2/3)*sqrt(3)/a, (1, 2) = 0, (2, 1) = -(1/3)*sqrt(3)/a, (2, 2) = -1/a, (3, 1) = -(1/3)*sqrt(3)/a, (3, 2) = 1/a})

(1)

Iload := <i[T]*exp(-I*Phi[T])|I*i[M]*exp(-I*Phi[M])>;

Vector[row](2, {(1) = i[T]*exp(-I*Phi[T]), (2) = I*i[M]*exp(-I*Phi[M])})

(2)

alpha := exp(I*convert(120*degrees, radians));

-1/2+((1/2)*I)*3^(1/2)

(3)

ABC2SEQ :=  1/3 * <<1,1,1> | <alpha, alpha^2, 1> | <alpha^2, alpha, 1>>;

Matrix(3, 3, {(1, 1) = 1/3, (1, 2) = -1/6+((1/6)*I)*sqrt(3), (1, 3) = (1/3)*(-1/2+((1/2)*I)*sqrt(3))^2, (2, 1) = 1/3, (2, 2) = (1/3)*(-1/2+((1/2)*I)*sqrt(3))^2, (2, 3) = -1/6+((1/6)*I)*sqrt(3), (3, 1) = 1/3, (3, 2) = 1/3, (3, 3) = 1/3})

(4)

Iabc := M2[transform] . (Iload^(%T));

Vector(3, {(1) = (2/3)*sqrt(3)*i[T]*exp(-I*Phi[T])/a, (2) = -(1/3)*sqrt(3)*i[T]*exp(-I*Phi[T])/a-I*i[M]*exp(-I*Phi[M])/a, (3) = -(1/3)*sqrt(3)*i[T]*exp(-I*Phi[T])/a+I*i[M]*exp(-I*Phi[M])/a})

(5)

Iabcx := subs[eval]({a=1.0} , Iabc);

Vector(3, {(1) = .6666666667*sqrt(3)*i[T]*exp(-I*Phi[T]), (2) = -.3333333333*sqrt(3)*i[T]*exp(-I*Phi[T])-(1.000000000*I)*i[M]*exp(-I*Phi[M]), (3) = -.3333333333*sqrt(3)*i[T]*exp(-I*Phi[T])+(1.000000000*I)*i[M]*exp(-I*Phi[M])})

(6)

Ipnz := ABC2SEQ . Iabcx:

simplify( Ipnz );

Vector(3, {(1) = (.5773502693-0.6000000000e-10*I)*i[T]*exp(-I*Phi[T])+.5773502694*i[M]*exp(-I*Phi[M]), (2) = (.5773502693-0.6000000000e-10*I)*i[T]*exp(-I*Phi[T])-.5773502694*i[M]*exp(-I*Phi[M]), (3) = 0.})

(7)

 


 

Download Q20200727_2.mw

Having read-only, public proprty of class is very useful. But I am not able to see if Maple supports this.

The idea is to have an object with public variable that can only be read from outside. But to change it, one must call a setter() method.  The advantage of this over having a getter() method to read the variable back is that it simplifies the code and makes it easier to read.  

There is good discussion here on this subject https://www.python-course.eu/python3_properties.php  

and https://en.wikipedia.org/wiki/Property_(programming)  :


"A property, in some object-oriented programming languages, is a special sort of class member, intermediate in functionality between a field (or data member) and a method. The syntax for reading and writing of properties is like for fields, but property reads and writes are (usually) translated to 'getter' and 'setter' method calls. The field-like syntax is easier to read and write than many method calls"

 

In Maple, if I make the variable inside the object an export then now one can not only read it, but also change it from outside. I want to allow only reading from outside. Here is an example

restart;
module my_class()
  option object;

  export name::string; #made it export to allow direct reading
 
  export set_name::static:=proc(o::my_class,name::string)
      o:-name := name;
  end proc;

end module;

And now one can do

o:=Object(my_class);
o:-set_name(o,"me");
o:-name;  #read it

But one can also change it from outside by doing o:-name:="new name";  and this ofcurse breaks the whole idea of encapsulation.

I think allowing reading only of object variables is OK and many OO language allow this. They are called properties.

If the variable above is made local, then one can not read it directly, and a getter() method is needed for each object properties, in addition to setter() method.

Is it possible in Maple to make local object variables read only from outside? If not and if Maplesoft wants to improve its OO, this will be something useful to add for next version.

Find x182 given that

 

x0=2.25

x1=1.75

xn= (1/6)*(sqrt(4+x(n-1))/(x(n-2))

 

and enter your answer correct to 10 significant figures in the box below.

To check that your calculations are correct, you should be able to calculate that  x93 is approximately 0.1348891.

[Note that you should do your calculations correct to 10 significant figures. Use ]

 

     x182=    Preview Change entry mode  

The terms of a sequence an are generated by the recurrence relation

a(n+1)=a(n)−2a(n−1)+a(n−2) for n=3,4,5,...

 

Using your Maple worksheet, write a for loop to find the value of a50 given that

a1=2,a2=-1 and a3=0

 

Copy (Ctrl-C) the correct value of a50 from your Maple worksheet and paste (Crtl-V) it in th answer box.

Preview Change entry mode 

 

 

Hi

When I try to substitute a value for j, it doesn't evaluate.

add.mw

Hi, I'm having trouble setting up a procedure for an assignment, we're trying to find root mean square error and remove variable by variable to find the best line of fit etc etc... hopefully from the coding you can see what I'm am trying to do, but I don't understand why it is not working? I wonder if it has something to do with the X and Y being read in?
 
M:=readdata("C:\\Users\\bjense04.CSUMAIN.001\\Documents\\ass1Q2.txt",[float,float,float,float,float]):
convert(M,matrix):
with(LinearAlgebra):
n:=RowDimension(convert(M,matrix));
X:=convert(M[1..n,1..4],matrix):
Y:=convert(M[1..n,5..5],vector):
with(Statistics):
FullEQN:=LinearFit([1,a,b,c,d],X,Y,[a,b,c,d]);
#the next part is incomplete
rmse_mlr:=proc(Full)
local i, sq, n, predicted;
sq:=0:
for i from 1 to n do
 predicted:=subs([a=X[i,1],b=X[i,2],c=X[i,3],d=X[i,4]],Full);
 sq:=sq+(Y[i]-predicted)^2;
end do:
return sqrt(sq/n);
end proc;
 
 
I then test the procedure with 
rmse_mlr(FullEQN,X,Y);
 
and the response i get is

Error, (in rmse_mlr) final value in for loop must be numeric or character
 
help?

Does anyone know why pdetest is not giving [0, 0, 0] for the solution of pdsolve?
 

restart

eq := diff(u(x, t), t)-k*(diff(u(x, t), x, x)) = 0

diff(u(x, t), t)-k*(diff(diff(u(x, t), x), x)) = 0

(1)

ic := u(x, 0) = g(x)

u(x, 0) = g(x)

(2)

bc := (D[1](u))(0, t) = 0, eval(diff(u(x, t), x)+u(x, t), x = 1) = 0

(D[1](u))(0, t) = 0, eval(diff(u(x, t), x), {x = 1})+u(1, t) = 0

(3)

sol := `assuming`([simplify(pdsolve([eq, ic, bc]))], [k > 0, 0 < x and x < 1, t > 0])

u(x, t) = `casesplit/ans`(Sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And((sin(lambda[n])*lambda[n]-cos(lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])})

(4)

`assuming`([simplify(pdetest(sol, [eq, ic, bc]))], [k > 0, 0 < x and x < 1, t > 0])

[-(diff(diff(`casesplit/ans`(sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])}), x), x))*k+diff(`casesplit/ans`(sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])}), t), `casesplit/ans`(Sum(4*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])})-g(x), eval(diff(`casesplit/ans`(Sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])}), x), {x = 0}), eval(diff(`casesplit/ans`(Sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])}), x), {x = 1})+`casesplit/ans`(Sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n])*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])})]

(5)

``


 

Download PDE.mw

inside my module, I create types to be used by only procs, and other sub modules inside the main one package I have.

but TypeTools:-AddType invoked inside my package, adds the type to system. So a user after loading the package can still see it and use this type.

Adding local before TypeTools:-AddType is not supported.

How to make the type only visible inside the package? Here is example

restart;
kernelopts('assertlevel'=2):
my_pkg:=module()
 option package;
 TypeTools:-AddType(age_type,t->evalb(t::nonnegint and t<150));
 export foo:=proc()
    local age::age_type:=20;
    print("age=",age);
 end proc;
end module;

with(my_pkg);

And now a user can do this

x::age_type:=30;

It worked, since age_type is now in the system. This can also cause a problem, since loading this package, could overwrite a type name allready set there by another package the user happened to load before.

If I can make it at least such that the user has to do 

x::my_pkg:-age_type:=200;

That would be better. But the best solution is to make the type name completely not visible from outside the package. i.e. private type to the package only.

I looked at Extension Mechanisms under typetools in help, but do not see how to use that for what I want.

 

Maple 2020.1

f[2](x) = -(3*R^2*x^11)/30800 + R^2*x^9/420 - (177*R^2*x^7)/9800 + M1*M2*x^5/40 + (17*R^2*x^5)/700 + ((-(3*M1*M2)/10 - (443*R^2)/21560)*x^3)/6 + (M1*M2/40 - (137*R^2)/26950)*x

Hi,

I am writing the following code and MAPLE is giving me operator error. Please help (file: doubt_6.mw)

d2:=100000000

for m in set_m do
    for n in set_n do
        SOL1 := fsolve({ODE11, ODE12}, {N, t__2});
        N1:=eval(N,SOL1);
        t_2_1 :=eval(t__2,SOL1);
        T_1:= eval(T, [lambda = 3, a = 300, b = .15, c = .25, A__m = 300, A__d = 150, A__r = 50,C__m = 4, P__m = 8, P__d = 10, 
        P__r = 12, theta__m = .15, theta__d = .12, theta__r = 0.5e-1, h__m = .2, h__d = .3, h__r = .5, i__m = .1, i__d = .1, 
        i__r = .1, i__om = .1, i__OD = .15, i__c = .3, i__e = .2, M = 2, alpha = 0.2e-1, t__2 = t_2_1]):
        t_31:= T_1 /m ;
        t_41:= T_1 /(m*n) ;
        if (N1<=t_41 and 2>=t_31) then
            d1:= eval(TCS__1, [lambda = 3, a = 300, b = .15, c = .25, A__m = 300, A__d = 150, A__r = 50, C__m = 4, P__m = 8, 
            P__d = 10, P__r = 12, theta__m = .15, theta__d = .12, theta__r = 0.5e-1, h__m = .2, h__d = .3, h__r = .5, i__m = .1, 
            i__d = .1, i__r = .1, i__om = .1, i__OD = .15, i__c = .3, i__e = .2, M = 2, alpha = 0.2e-1, t__2=t_2_1, N=N1]):
            if (d1<= d2) then
                d2:= d1;
                print("Value is updated",d2,N1,t_2_1,"for",m,n)
            end if
        end if    
        print(N1,t_2_1,t_31,t_41,d1,m,n)
    end do
end do

 

Thanks in advance

Any idea why Maple can simplify this expression only when multiplied by -1 but not otherwise?

expr:=sqrt(-2 + 2*I*sqrt(3));
simplify(expr)

But now

simplify(-1*expr)

Multiplying by -1 should not have mattered. Becuase -2 + 2*I*sqrt(3)=(1+I*sqrt(3))^2  Therefore sqrt(-2 + 2*I*sqrt(3)) is the same as 1+I*sqrt(3) and Maple knows this:

simplify((1 + sqrt(3)*I)-expr) gives zero.

But Maple only simplifies -expr  and not +expr.

Just wondering is someone can suggest why that is and if this is considered OK?

Maple 2020.1, Physics 724

First 401 402 403 404 405 406 407 Last Page 403 of 2308