Python Forum
Parameterized math calculations?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parameterized math calculations?
#1
Question 
Is there a way to do maths in python that results in parameterized solutions?

For example 2a+3a = 5a

What I want to do is, to use an algorithm named as Runge-Kutta 4th order to the following differential equations

Y'(t) = -aY(t)E(t)
E'(t) = aY(t)E(t) - bE(t)
T'(t) = bE(t)

I know the values of E(t), Y(t), T(t) at any time t, but I need to find a and b.

In hand, I know how to do this. I just need to do 110 loops from 0 to 109 for each of the 3 diff equations. This will result in three
parameterized equations E(109), Y(109), T(109) that include the a and b. And then I need to solve a 3x2 system to
find a and b.

The problem is that in Python and any programming language, you can only calculate numbers. Not equations and
then solve a system...

Thank you!
Reply
#2
Quote:The problem is that in Python and any programming language, you can only calculate numbers. Not equations and
then solve a system...
???
see https://numpy.org/
babaliaris likes this post
Reply
#3
It looks like you want to brute force the problem without an initial mathematical study. I don't think it is the best approach.

In fact you could ask Python to compute with formal parameters a and b with the sympy module, but if you do that with 100 steps of a Runge-Kutta method, you will probably get huge formal expressions in a and b that won't help you solve the problem. Indeed evaluating these expressions for a particular value of (a, b) will not be more efficient than running the Runge-Kutta method again for this particular value of the parameter.

I think a minimal mathematical study of the problem is necessary. First remark that you don't have 3 equations but 2. Indeed, the system implies that Y + E + T is a constant, in particular, a necessary condition for solvability is that Y + T + E has the same values at the initial time and the final time. That said, you can safely ignore the 3rd equation and work only with a problem in the (Y, E) plane.

The second remark is that if we define Y(t) = (b/a) y(b t) and E(t) = (b/a) e(b t), then y(t) and e(t) are solutions of equations without parameters

y' = - y e
e' = y e - e

It means that you have a single vector field to study, the first thing to do is to draw the phase portrait of this vector field to understand the structure of the trajectories.

With this vector field, if you take an initial point (y(0), e(0)) which is a multiple of your known initial condition (Y(0), E(0)), you can compute by Runge-Kutta the position of (y, e) the first time that it is a multiple of your known final position (Y1, E1). If it is the same multiple, then the value of the multiple is a/b and the time is b t1 which means that you can compute a and b.

Thus the problem reduces to studying a kind of Poincaré map from a radial half line to another one and find a fixed point of this map. The values of the map can be computed numerically with Runge-Kutta. Further mathematical investigations of this map could be immensely helpful, but you could already apply an equation solver by bisection to this map.
babaliaris likes this post
Reply
#4
(May-30-2022, 08:43 AM)Gribouillis Wrote: The second remark is that if we define Y(t) = (b/a) y(b t) and E(t) = (b/a) e(b t), then y(t) and e(t) are solutions of equations without parameters

y' = - y e
e' = y e - e

I struggle to understand this. I tried some math myself but I don't see anything. Could you please use a more descriptive proof of this?

[Image: 1654016836769.jpg]

Thank you!
Reply
#5
Have you ever heard of the chain rule? paste this latex code here https://latex.codecogs.com/eqneditor/editor.php
Output:
\left\{\begin{matrix} -a \frac{b}{a} y(bt) \frac{b}{a} e(bt) = - a Y(t) E(t) = Y'(t) = \frac{b}{a}\ b\ y'(bt)\\ \Rightarrow - y(bt) e(bt) = y'(bt)\\ a \frac{b}{a} y(bt) \frac{b}{a} e(bt)-b\frac{b}{a} e(bt) = a Y(t) E(t)-bE(t)=E'(t) = \frac{b}{a}\ b\ e'(bt)\\ \Rightarrow y(bt) e(bt) - e(bt) = e'(bt)\\ \end{matrix}\right.
Reply
#6
I guess I'm not smart enough? (I know what the chain rule is)

I truly can not understand:

1) How did you come up with these definitions?
2) Why does this "method" stands mathematically?
3) Are y' = y'(t) and e' = e'(t)?
4) How am I going to calculate y(bt), e(bt) if I need it in the Runge-Kutta method? You mentioned something about multiple of Y(t), E(t)?

Thank you and sorry.
Reply
#7
(May-31-2022, 07:14 PM)babaliaris Wrote: 1) How did you come up with these definitions?
Well I just felt that due to the fact that the equation has only linear and quadratic terms, it could be possible to eliminate the constants a and b from the equations by scaling the time and the solution with an ad hoc factor. This idea is classical in the field of ODE and PDE, it is related to the techniques of nondimensionalization.
(May-31-2022, 07:14 PM)babaliaris Wrote: 2) Why does this "method" stands mathematically?
If t ⟶ (y(t), e(t)) is a trajectory of the second system (without a and b), then t ⟶ (Y(t), E(t)) := ((b/a) y(bt), (b/a) e(bt)) is a trajectory of the first system and conversely. So there is a one to one correspondance between the trajectories of the two systems. The only problem is that we don't know (a, b), but it is true that the vector (Y, E) at time t is a multiple of the vector (y, e) at time b t. The factor between the two is (b/a)
(May-31-2022, 07:14 PM)babaliaris Wrote: 3) Are y' = y'(t) and e' = e'(t)?
The relation y' = - y e holds at any moment, so it can be y'(t) = - y(t) e(t) or y'(b t) = - y(b t) e(b t) etc. This is not important
(May-31-2022, 07:14 PM)babaliaris Wrote: 4) How am I going to calculate y(bt), e(bt) if I need it in the Runge-Kutta method? You mentioned something about multiple of Y(t), E(t)?
Suppose that you know the initial position (Y0, E0) at time t=0 and the final position (Y1, E1) at time t1. Your problem is to find (a, b) such that the trajectory starting from (Y0, E0) reaches (Y1, E1). In terms of (y, e) we know that initially (y0, e0) is a multiple of (Y0, E0), that is to say (y0, e0) = u * (Y0, E0) but we don't know u which should be equal to a/b. We apply Runge Kutta to the second system, starting from u * (Y0, E0) and we run the method until (y, e) is a multiple of (Y1, E1), say (y1, e1) = v * (Y1, E1). This defines a mapping P: u ⟶ v from (0, inf) to (0, inf). Our problem is to find a value u such that P(u) = u. Indeed in this case we have u = a/b and t = b t1 where t is the time computed by the algorithm to reach this position.
Reply
#8
I discovered something even more interesting in the second system, one can simply remove time because

(e + y - ln(y))' = ye - e - ye + ye/y = 0

It means that e + y - ln(y) is constant along the trajectories. In particular it mean that

v(E1 + Y1) - ln(v Y1) = u (E0 + Y0) - ln(u Y0)

Then you don't need Runge-Kutta anymore, let us simply write that v = u, which leads to the equation

u (E1 + Y1 - E0 - Y0) = ln(Y1) - ln(Y0)

hence a/b = u = (ln(Y1) - ln(Y0))/(E1 + Y1 - E0 - Y0)

The time interval can then be computed by a simple integral, thus giving b and a.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  math.log versus math.log10 stevendaprano 10 2,427 May-23-2022, 08:59 PM
Last Post: jefsummers
  Python, how to manage multiple data in list or dictionary with calculations and FIFO Mikeardy 8 2,620 Dec-31-2021, 07:47 AM
Last Post: Mikeardy
Photo Filtering data and precision during calculations Scientifix 0 1,788 Mar-30-2021, 01:00 PM
Last Post: Scientifix
  List calculations rturus 1 1,815 Mar-23-2021, 04:40 PM
Last Post: deanhystad
  Why getting ValueError : Math domain error in trig. function, math.asin() ? jahuja73 3 3,782 Feb-24-2021, 05:09 PM
Last Post: bowlofred
  Automation in calculations interdisciplinary 5 2,712 Dec-10-2020, 11:22 PM
Last Post: deanhystad
  Latitude&Longitude Calculations gdimit 3 3,815 Jan-30-2018, 07:47 AM
Last Post: buran
  Parameterized SQL query purnima1 1 4,562 Oct-10-2017, 03:08 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020