## 55 Reputation

9 years, 195 days

## Maximizing a function...

Maple 17

Hi there,

I am trying to maximize a function given a set of values to a parameter in the function. The function is an differential equation belonging to a system of two differential equations.

I have a for loop to state different values to the parameter.

Maple yields the error:

Error, (in Optimization:-NLPSolve) cannot evaluate the solution further right of 0.17757507e-4, probably a singularity

When trying to maximize the function.

Supposed that I was doing something wrong in the loop, if I reproduce the contents of the loop outside, and set a value for the parameter. If I plot the solution of the ordinary differential equation, I can see where the maximum lies.

Having plot it, the Optimizamtion:-Maximize works as expected.

However, omitting the plot has a weird effect: I only get the same result depending on the bounds I set for the Maximization:

de1 := diff(A(t), t) = r*m*(1-g)*A(t)-piecewise(t < 8, r*A(t), t >= 8, (r+k)*A(t));
de2 := diff(G(t), t) = r*m*g*A(t)-l*G(t);

ics := A(0) = 25.0, G(0) = 0.;
num := dsolve({de1, de2, ics}, {A(t), G(t)}, type = numeric, output = listprocedure, parameters = [g]);

num(parameters = [g = .15]);
val := eval(G(t), num);

# odeplot(val, [t, G(t)], t = 0 .. 100);

Maximize(val);
Error, (in Optimization:-NLPSolve) cannot evaluate the solution further right of 0.17757507e-4, probably a singularity

val2 := Maximize(val);

Error, (in Optimization:-NLPSolve) cannot evaluate the solution further right of 0.17757507e-4, probably a singularity

val3 := Maximize(val(t), t = 0 .. 60);

[10267.824035766165, [t = 8.25727747134303]]

val4 := Maximize(val(t), t = 0 .. 100);

[6.863211343195069e-9, [t = 59.84184367042171]]

The right answer is [10267.824035766165, [t = 8.25727747134303]]: Why do I get two different answers even if in that range there is only one relative maximum?

I ignore whether the way I am specifying the arguments for the Maximize function is correct. val is a procedure.

What am I missing?

Attached is the worksheet: MaplePrimes_malaria_param_variation_2.mw

Thanks,

jon

## Solving integrals...

Maple 17

Hi there,

I would like to use Maple to solve a couple of integrals.

My attempt seems to have some errors, since even if the integral expressions are rendered correctly, they are  not being solved. They shouldn't need numeric methods to be solved.

The integrals are the following:
G1 := int(e^((lambda-k)*s-e^(-k*s)), s = -infinity..t);
G := int(e^(-(lambda+k)*t-e^(-k*t))*G1, t = -infinity..infinity);

Thus:

and

And attached is the unsuccessful attempt: MaplePrimes_Lea-Catcheside.mw

Thanks,
jon

## Analyzing a differential equation system...

Maple 17

Hi there,
I have a set of differential equations whose solution, Jacobian matrix and its eigenvalues, direction field, phase portrait and nullclines, need to be computed.

Each of the equations has a varying parameter.

I know how to get the above for a single parameter value, but when I set a range of values for the parameters, Maple is not able to handle all cases as I would expect: solving the differential equation system:

eq1 := x*(1.6*(1-(1/100)*x)-phi*y)
eq2 := (x/(15+x)-0.3e-1*x-.4)*y+.6+theta
desys := [eq1, eq2];
vars := [x, y];

Error, (in unknown) invalid input: Utilities:-SetEquations expects its 2nd argument, equations, to be of type set({boolean, algebraic, relation}), but received {-600*y+(Array(1..2, {(1) = 8400, (2) = 15900})), Array(1..5, {(1) = 0, (2) = 0, (3) = 0, (4) = 0, (5) = 0})}

The equations are the following:
de1 := diff(x(t), t) = x(t)*(1.6*(1-(1/100)*x(t))-phi*y(t));
de2 := diff(y(t), t) = (x(t)/(15+x(t))-0.3e-1*x(t)-.4)*y(t)+.6+theta

the parameters being:
phi:=[0 0.5 1 1.5 2]
theta:=[5. 10.]

How can I handle the situation so that Maple computes each of the above for each combination of the parameters?

I would like to avoid using two for loops and having to store all results in increasingly bigger and complicated arrays.

The worksheet at issue is this: MaplePrimes_Tumour_model_phi_theta_variation.mw

Thanks,
jon

## Parentheses and units in odeplot legend...

Maple 17

Hi there,
I am wondering how to print parentheses in the legend of an odeplot.

The following command

odeplot(numsolnf, [[t, CECnf(t)], [t, VECnf(t)], [t, CICnf(t)], [t, VICnf(t)]], 0..50, opts, legend = ['Extracelular urea concentration (mg/dL)', 'Extracelular urea volume (L)', 'Intracelular urea concentration (mg/dL)', 'Intracelular urea volume (L)'])

where numsolnf is the numerical solution of the equation system composed by CECnf(t), VECnf(t), CICnf(t), and
VICnf(t) produces no parentheses.

And the "Extracelular urea concentration (mg/dL)" and "Intracelular urea concentration (mg/dL)" are displayed as if the whole text was a quotient:

Extracelular urea concentration mg
dL

Any ideas about how to solve these issues?

Thanks,
jon

## Combine two arrays element-wise...

Maple 17

Hi there,

this may be a common task but did not find any helpful hint nor an answer: is there any way to combine to arrays A and B into another one element-wise, i.e.:
C = [[A[1],B[1]], [A[2],B[2]],...,[A[N],B[N]]]
without doing a for loop?

Thanks,
jon

 1 2 3 4 Page 2 of 4
﻿