MaplePrimes Questions

Hi,
I have a function "w" that the eval command does not gives the correct value of its first derivative at a fixed point. I guess the problem is due to sqrt() terms, but I can't fix it. 
eval.mw

Hello everyone! I have found this document from Maple 18 (2014) that will be very usefull for my school work, but when i copy it into Maple 2022 i get the error message, "action, does not evaluate to a module" Is there any way for me to fix this? What i have been able to read is that i have to go in and update the code, but i have absolute no idea on how to do it? 

Kind Regards Samuel 

Regressionmodeller._Skal_laves_til_maple_22_og_23.mw

How can I plot stream lines between two concentric spheres?

Hi,

I am using Maple 2020 to numerically solve/generate numerical plots for my impulsive control problem.

The optimal control problem is:

T is time from0 to T where T is the terminal time

K(t), B(t) and M(t) are state variables

w(t) is a control variable

a(ti) is the impulsive control variable at time ti,

a(ti) \in [0,1] for i=1,2,…,N

ggamma, ttheta, ddelta1, ddelta 2, c1 and c2 are constants

K(T)=M(T)=0 B(T)>0

K'(t)=ggamma*K(t)*w(t)-ttheta*M(t)

B’(t)=ggamma*K(t)+ttheta*M(t)*B(t)

M’(t)=M(t)-ggamma*w(t)

M(ti)=M(ti-)+a(ti)M(ti)*ddelta1

K(ti)=K(ti-)-a(ti)K(ti)*ddelta2

Objective: maximize B(T)-integral from 0 to T of c1*(w(t))^2dt-sum i=1 to N of c2*a(ti)

Here is the code I enter to MAple:

restart;

# Define the constants
ggamma := 1.0;
ttheta := 2.0;
ddelta1 := 0.1;
ddelta2 := 0.2;
c1 := 0.5;
c2 := 0.3;
T := 5.0; # Terminal time

# Define the impulsive changes in M(t)
impulse_changes := proc (t)
    local ti_values, imp_values, result;
    ti_values := [1.0, 2.0, 3.0]; # Example impulsive time instants
    imp_values := [0.2, 0.1, 0.3]; # Corresponding impulsive control values
    result := 0;
    for i from 1 to nops(ti_values) do
        if t = ti_values[i] then
            result := result + imp_values[i]*M(ti_values[i])*(ddelta1 - ddelta2);
        end if;
    end do;
    return result;
end proc;

# Define the system of differential equations
diffeqs := {diff(K(t), t) = ggamma*K(t)*w(t) - ttheta*M(t),
            diff(B(t), t) = ggamma*K(t) + ttheta*M(t)*B(t),
            diff(M(t), t) = M(t) - ggamma*w(t)};

# Define the impulsive controls
impulse_controls := [1.0, 0.5, 0.8]; # Example impulsive control values

# Define the initial values and conditions
initial_values := [K(0) = 0, B(0) = 0, M(0) = 0];

# Define the final conditions
final_conditions := [K(T) = 0, M(T) = 0, B(T) > 0];

# Define the objective function to be maximized
objective := B(T) - int(c1*w(t)^2, t = 0 .. T) - add(c2*impulse_changes(ti), ti = 1.0 .. 3.0);

# Solve the system of differential equations numerically
sol := dsolve({diffeqs, initial_values, final_conditions}, numeric, output = listprocedure);

# Find the optimal control trajectory w(t) using optimization
w_optimal := optimize(objective, numeric, maximize);

# Evaluate the optimal control and state trajectories
optimal_controls := [seq(w_optimal(t), t = 0.0 .. T, 0.1)];
state_trajectories := [sol[2](t), sol[3](t), sol[4](t)];

optimal_controls, state_trajectories;

I am getting the error:

"Error, (in dsolve/numeric/process_input) system must be entered as a set/list of expressions/equations"

as soon I run after the sol:= function.

I would appreciate any help with fixing my code!

Thank you very much!

Hafiz_basin_of_attraction_.mw

[moderator: see also this earlier Question]

Hi Users!

I hope everyone is fine. I want to plot any function say
f := exp(cos(x)+sin(x)) for x=a..b for any n say 12 so that h := (b-a)/n. 

For a=0, b=3 and n=12 I got h=1/4 and plot of f is:

But I want the plotting as given bellow where the value of f(x) is mentioned and girds line.

I am waiting for your answer. Thanks in advance.

 

Just wanted to ask, what the issue here is:

restart;
Int(1/(1 - x*ln(x)), x);
IntegrationTools:-Change(%,u=1-x*ln(x),u);

doesn't give the proper transformation. It gives

Int(1/u,u)

Solving for x and writing the transformation in terms of LambertW gives something else, if I'm not mistaken.

Dear Users!

I hope everyone is fine here. I wrote the following statements with the print command:

restart; NN := [4, 6, 8]; a := 0; b := 2; n := 4;
h := evalf((b-a)/n); print("The domain of intergation is [a,b] = ", [a, b]);
f := exp(x); print("The given function is ", f);
Exact := evalf(int(f, x = a .. b)); print("The exact integration in [a,b] is ", Exact);
print("The value of h to divide the domain [a,b] into n subintervals is ", h);
print("Numerical integration in [a,b] is going to perform when h via RECTANGULAR METHOD for n = ", n);

The output is:

                          0.5000000000
        "The domain of integration is [a,b] = ", [0, 2]
                "The given function is ", exp(x)
       "The exact integration in [a,b] is ", 6.389056099
"The value of h to divide the domain [a,b] into n subintervals is ", 0.5000000000
"Numerical integration in [a,b] is going to perform when h via RECTANGULAR METHOD for n = ", 4

I want the actual values of a,b, n and h highlighted in above as:

                            0.5000000000
        "The domain of integration is [a,b] = ", [0, 2]
                "The given function is ", exp(x)
       "The exact integration in [0,2] is ", 6.389056099
"The value of h to divide the domain [0,2] into 4 subintervals is ", 0.5000000000
"Numerical integration in [0,2] is going to perform when 0.5 via RECTANGULAR METHOD for n = ", 4

The code below runs as expected up through the 4th line. At that point ans_all should contain all the multipule ansers to the equation being looked at. I want to look at just the first solution and I would expect the way to do this would be ans_all[1]. However the command ans_all[999999999] is valid, which indicates to me that that's not how you do that. So.... how do I get just the first answer?

equ := sqrt(1 + (-4 + 4*sqrt(2))*x + (16 - 12*sqrt(2))*x^2 + (-24 + 16*sqrt(2))*x^3 + (15 - 8*sqrt(2))*x^4)/(1 + (-4 + 4*sqrt(2))*x + (22 - 12*sqrt(2))*x^2 + (-36 + 28*sqrt(2))*x^3 + (33 - 20*sqrt(2))*x^4):
anit_dev_equ := int(equ,x):
ans_root := eval(anit_dev_equ, [x = 1]) - eval(anit_dev_equ, [x = 0]):
ans_all := allvalues(ans_root):
ans_all[999999999]

could any one help  to plot this.

Here is my code.

PWS.mw

I need to make the graph i have attached match the image below.

Is there any wrong with unknown parameter i found?How to solve this.Please Help.

Dear Maple professionals

I have written two procedures in Maple that are run flawlessly. But when I wrote a simple third procedure that calls those two, I face an error. Can you guide me if I am missing anything? The code is attached. Thank you in advance!
 

``

restart

with(plots)

c := 1; cr := 0.3e-1*c; u := 1; sExp := 0.6e-1*c; s := .65*c

v := 3*c

NULL

FirmModelPP := proc (alpha, delta) local p0, xi0, q0, Firmpf0, G0, Recpf0, Unsold0, Environ0; option remember; xi0 := 1; p0 := min(s+sqrt((v-s)*(c-s)), delta*v+sExp); q0 := u*(v-p0)/(v-s); f(N) := 1/u; F(N) := N/u; G0 := int(F(N), N = 0 .. q0); Firmpf0 := (p0-c)*q0-(p0-s)*G0; Recpf0 := (sExp-cr)*xi0*q0; Environ0 := q0+G0; Unsold0 := G0; return p0, q0, Firmpf0, Recpf0, Unsold0, Environ0 end proc

FirmModelFC := proc (alpha, beta, delta) local p00, xi00, q00, Firmpf00, G00, Recpf00, Unsold00, Environ00, pr00; option remember; xi00 := 1; p00 := s+sqrt((v-s)*(c-s)); if p00 < delta*v+sExp then q00 := u*(v-p00)/(v-s); f(N) := 1/u; F(N) := N/u; G00 := int(F(N), N = 0 .. q00); Firmpf00 := (p00-c)*q00-(p00-s)*G00; Recpf00 := `&xi;00*q00*`(sExp-cr); Unsold00 := G00; Environ00 := q00+Unsold00 else q00 := alpha*u*(v-p00)/(v-s); f(N) := 1/u; F(N) := N/u; G00 := int(F(N), N = 0 .. q00/alpha); pr00 := p00-delta*v; Firmpf00 := (p00-c)*q00-alpha*(p00-s)*G00; Recpf00 := (beta*(pr00-sExp)+sExp-cr)*xi00*q00-(1/2)*(pr00-sExp)*beta^2*xi00^2*q00^2/(u*(1-alpha)); Unsold00 := G00; Environ00 := q00+Unsold00 end if; return p00, q00, Firmpf00, Recpf00, Unsold00, Environ00 end proc

NULL

NULL

"CurrentMetrics:= proc(alpha,beta,delta) option remember;  local  p, q, Firmpf,Recpf,Unsold,Environ; "

Error, unterminated procedure

"CurrentMetrics:= proc(alpha,beta,delta) option remember;  local p, q, Firmpf,Recpf,Unsold,Environ; "

 

"if (FirmModelFC(alpha,beta,delta)[3]>=FirmModelPP(alpha,delta)[3]) then    p:=FirmModelFC(alpha,beta,delta)[1]:  q:=FirmModelFC(alpha,beta,delta)[2]:   Firmpf:=FirmModelFC(alpha,beta,delta)[3]:  Recpf:=FirmModelFC(alpha,beta,delta)[4]:  Unsold:=FirmModelFC(alpha,beta,delta)[5]:   Environ:=FirmModelFC(alpha,beta,delta)[6]:     else   p:=FirmModelPP(alpha,delta)[1]:  q:=FirmModelPP(alpha,delta)[2]:   Firmpf:=FirmModelPP(alpha,delta)[3]:   Recpf:=FirmModelPP(alpha,delta)[4]:  Unsold:=FirmModelPP(alpha,delta)[5]:   Environ:=FirmModelPP(alpha,delta)[6]:    end if :  return p,q,Firmpf,Recpf, Unsold,Environ;  end proc: "

Error, unable to parse

"if (FirmModelFC(alpha,beta,delta)[3]>=FirmModelPP(alpha,delta)[3]) then p:=FirmModelFC(alpha,beta,delta)[1]:  q:=FirmModelFC(alpha,beta,delta)[2]:   Firmpf:=FirmModelFC(alpha,beta,delta)[3]: Recpf:=FirmModelFC(alpha,beta,delta)[4]:  Unsold:=FirmModelFC(alpha,beta,delta)[5]: Environ:=FirmModelFC(alpha,beta,delta)[6]:    else p:=FirmModelPP(alpha,delta)[1]:  q:=FirmModelPP(alpha,delta)[2]:   Firmpf:=FirmModelPP(alpha,delta)[3]: Recpf:=FirmModelPP(alpha,delta)[4]:  Unsold:=FirmModelPP(alpha,delta)[5]: Environ:=FirmModelPP(alpha,delta)[6]:   end if :  return p,q,Firmpf,Recpf, Unsold,Environ;  end proc: "

 

NULL

plot(['CurrentMetrics(alpha, .2, .2)[3]'], alpha = 0. .. 1.0, linestyle = [solid], legend = ["Firm's profit with delta=0.2"], labels = [alpha, "Firm profit"], labeldirections = ["horizontal", "vertical"], color = [blue], axes = boxed)

Warning, unable to evaluate the function to numeric values in the region; see the plotting command's help page to ensure the calling sequence is correct

 

 

NULL

NULL

NULL

NULL

NULL

NULL


 

Download Call_two_procedures_in_another_one.mw

 

How does a user retain existing inline output (for example, computational output or inline plots) when re-executing an execution group in recent versions of Maple?  The "Replace existing output when re-executing groups" option is not available in Maple 2023 or in Maple 2020.

For example, I want to execute the same execution group 2 times to generate 2 different inline plots as the output. I want to retain the first inline plot when I generate the second inline plot.  However, the default Maple 2023 behavior is to overwrite the first inline plot with the second inline plot.

Several Maple versions ago (for example, Maple 18), there was the Tools > Option > Display > "Replace existing output when re-executing groups" option. When that option is checked, the second plot overwrites the first plot. In contrast, when that option is unchecked, the second plot appears after the retained first plot.

Where is the "Replace existing output when re-executing groups" option in recent Maple versions? Or do recent versions, like Maple 2023, use a different method to retain existing output when re-executing an execution group?

I think that the following worksheet is self-explaining: 
 

restartNULL

interface(version)

`Standard Worksheet Interface, Maple 2023.1, Windows 10, July 7 2023 Build ID 1723669`

(1)

evalf(LinearAlgebra:-MatrixFunction(`<|>`(`<,>`(1, 0, 0), `<,>`(1, 1, I), `<,>`(3, 0, 2)), 'x'/(exp('x')-1), 'x'))

Matrix(%id = 36893489913840207380)

(2)

(* Yet in many cases, the input may be inexact, for we need to speed up computations and decrease memory usage. *)

m := Matrix([[1, 1, 3], [0, 1, 0], [0, I, 2]], datatype = complex(sfloat)):
Digits := 10:
do
    print(CodeTools:-Usage(LinearAlgebra:-MatrixFunction(m, 'x'/(exp('x') - 1), 'x'), quiet), Digits++)
until Digits > 20:

Matrix(3, 3, {(1, 1) = .5819767069, (1, 2) = -.3333333333+.1931757357*I, (1, 3) = -.8068242642, (2, 1) = 0., (2, 2) = .5819767069, (2, 3) = 0., (3, 1) = 0., (3, 2) = -.2689414214*I, (3, 3) = .3130352855}), 10

 

Matrix(3, 3, {(1, 1) = .5819767069, (1, 2) = -.33333333332+.19317573586*I, (1, 3) = -.8068242642, (2, 1) = 0., (2, 2) = .5819767069, (2, 3) = 0., (3, 1) = 0., (3, 2) = -.2689414214*I, (3, 3) = .3130352855}), 11

 

Matrix(3, 3, {(1, 1) = .5819767069, (1, 2) = -.333333333321+.193175735853*I, (1, 3) = -.8068242642, (2, 1) = 0., (2, 2) = .5819767069, (2, 3) = 0., (3, 1) = 0., (3, 2) = -.2689414214*I, (3, 3) = .3130352855}), 12

 

Matrix(3, 3, {(1, 1) = .5819767069, (1, 2) = -.3333333333209+.1931757358526*I, (1, 3) = -.8068242642, (2, 1) = 0., (2, 2) = .5819767069, (2, 3) = 0., (3, 1) = 0., (3, 2) = -.2689414214*I, (3, 3) = .3130352855}), 13

 

Matrix(3, 3, {(1, 1) = .5819767069, (1, 2) = -.33333333332087+.19317573585263*I, (1, 3) = -.8068242642, (2, 1) = 0., (2, 2) = .5819767069, (2, 3) = 0., (3, 1) = 0., (3, 2) = -.2689414214*I, (3, 3) = .3130352855}), 14

 

Matrix(3, 3, {(1, 1) = .5819767069, (1, 2) = -.333333333320870+.193175735852624*I, (1, 3) = -.8068242642, (2, 1) = 0., (2, 2) = .5819767069, (2, 3) = 0., (3, 1) = 0., (3, 2) = -.2689414214*I, (3, 3) = .3130352855}), 15

 

Matrix(3, 3, {(1, 1) = .5819767068693265, (1, 2) = .9999999999999999-3.806824264*I, (1, 3) = -.8068242641099854, (2, 1) = 0., (2, 2) = .5819767068693265, (2, 3) = 0., (3, 1) = 0., (3, 2) = -.2689414214*I, (3, 3) = .3130352854993314}), 16

 

Matrix(3, 3, {(1, 1) = .58197670686932644, (1, 2) = .99999999999999997-3.806824264*I, (1, 3) = -.80682426410998598, (2, 1) = 0., (2, 2) = .58197670686932644, (2, 3) = 0., (3, 1) = 0., (3, 2) = -.2689414214*I, (3, 3) = .31303528549933112}), 17

 

Matrix(3, 3, {(1, 1) = .581976706869326423, (1, 2) = -.999999999999999997+2.19317573589001464*I, (1, 3) = -.806824264109985348, (2, 1) = 0., (2, 2) = .581976706869326423, (2, 3) = 0., (3, 1) = 0., (3, 2) = -.2689414214*I, (3, 3) = .313035285499331308}), 18

 

Matrix(3, 3, {(1, 1) = .5819767068693264245, (1, 2) = -.2500000000000000000-0.5682426411e-1*I, (1, 3) = -.8068242641099853627, (2, 1) = 0., (2, 2) = .5819767068693264245, (2, 3) = 0., (3, 1) = 0., (3, 2) = -.2689414214*I, (3, 3) = .3130352854993313037}), 19

 

Matrix(%id = 36893489913905117652), 20

(3)

# Is `linalg:-matfunc` better than `LinearAlgebra:-MatrixFunction`?!
Digits := 10:
linalg:-matfunc(m, 'x'/(exp('x') - 1), 'x');

Matrix(3, 3, {(1, 1) = .5819767070, (1, 2) = -.3386968877+.2092663986*I, (1, 3) = -.8068242645, (2, 1) = 0., (2, 2) = .5819767070, (2, 3) = 0., (3, 1) = 0., (3, 2) = -.2689414215*I, (3, 3) = .3130352855})

(4)

(*
Even for a 3×3 matrix, the number of digits has to be set to 20.
So … how can you certify that the following output is validated?
*)
_seed := 1234:

LinearAlgebra:-MatrixFunction(LinearAlgebra:-RandomMatrix(50, density = .5, generator = -2*Pi .. 2*Pi, datatype = complex[8]), 'x'/(exp('x')-1), 'x')

Warning, the use of _seed is deprecated.  Please consider using one of the alternatives listed on the _seed help page.

 

Matrix(%id = 36893490216779135924)

(5)


 

Download funm.mws

How do you confirm the validity of the last output? 

> op(3, eval(LinearAlgebra:-MatrixFunction));
 = 
  Copyright (c) 2002 Waterloo Maple Inc. All rights reserved.

And does this mean that LinearAlgebra['MatrixFunction'] is so out-dated that the return value is less effective in certain cases?

I'm presently checking the ability of inttrans:-laplace to give results one can find in the literature.
Unfortunately the inttrans:-laplace's  answers are sometimes more complex than those published in the literature and I'm not capable to simplify the output.

For instance

f := (t+1)/sqrt(t^2+2*t);
L := laplace((t+1)/sqrt(t^2+2*t), t, p);

expresses L in terms of WhittakerW and BesselK(0, p) functions as the answer simply is

exp(p)*BesselK(1, p)

Laplace.mw

How can I get this result with Maple?

TIA

By default, CodeGeneration generates temporary names during optimize of t####. For compatibility with other code, I would like to have flexibility in choosing the preamble to the temporary variable name ("t" is default). Is there a way to do this?

I don't see anything in the documentation, but it seems like something one should be able to do.

(My target language is Python - although I'm not really using Python, the syntax is compatible).

First 177 178 179 180 181 182 183 Last Page 179 of 2427