简体   繁体   中英

How to solve a function y=f(x,y), i.e, the functional value depends on itself

I want to solve the following equation in python. Problem is the dependent variable 'y' is also present in the right hand side of the equation as well. First question, how is such equations named in mathematics?

I can solve it if I skip the 'y' from the RHS. But no idea how to solve keeping it in place.

在此处输入图片说明

I used the following code: import numpy as np from matplotlib import pyplot as plt

A=2
B=1.3
C=0.25
D=1.25
def func(x,A,B,C,D):
  y=A*np.sinh(((x)/B-C)/D)  #I skipped (x-y) here
  return y

x=np.linspace(-3,3,200)
y=func(x,A,B,C,D)
plt.plot(x,y)
plt.show()

Such nonlinear equations are often solved in an iterative way. Set y=0 , solve equation, get new y , insert the new value in RHS and repeat the process. Track the value y(j)-y(j-1) to check the convergence. If it does not onverge, try to mix previous RHS part with a current one with a certain weight: RHS(j) = w * RHS(j) + (1-w) RHS(j-1) . Below is some usefull links about it:

wiki

Book: Iterative Solution of Nonlinear Equations in Several Variables By JM Ortega, WC Rheinboldt

Here is your example modified:

import matplotlib.pyplot as plt
A=2
B=1.3
C=0.25
D=1.25
def func(x,z,A,B,C,D):
  y=A*np.sinh(((x-z)/B-C)/D)  #I skipped (x-y) here
  return y

x=np.linspace(-3,3,200)
y = np.zeros(x.shape)
w = 0.4
d = 10
track_d = []

while d > 0.01:
    track_d.append(d)
    temp = y
    y = w * y + (1-w) * func(x,y,A,B,C,D)
    d = np.max(np.abs(temp-y))

y=func(x, y,A,B,C,D)
plt.plot(x,y)
plt.show()

plt.plot(track_d)
plt.show()

For larger interval it looks more interesting, pay attention to the parameter w.

import matplotlib.pyplot as plt
A=2
B=1.3
C=0.25
D=1.25
def func(x,z,A,B,C,D):
  y=A*np.sinh(((x-z)/B-C)/D)  #I skipped (x-y) here
  return y

x=np.linspace(-30,30,200)
y = np.zeros(x.shape)
w = 0.99999999
d = 10
track_d = []

while d > 0.0000001:
    track_d.append(d)
    temp = y
    y = w * y + (1-w) * func(x,y,A,B,C,D)
    d = np.max(np.abs(temp-y))

y=func(x, y,A,B,C,D)
plt.plot(x,y)
plt.show()
# look at the convergence
plt.plot(track_d)
plt.show()

在此处输入图片说明

Your equation can be very much simplified to obtain x as a function of y . First, we can rewrite your equation as follows:

y = a * sinh(b * x + c * y + d)

Note that this comes with some non-zero assumptions over A,B,C,D

b * x + c * y + d = arcsinh(y/a)

arcsinh can be rewritten using natural logarithm : b * x + c * y + d = ln(y/a + sqrt((y/a)**2 + 1)))

This gives:

x = (1/b) * (ln(y/a + sqrt((y/a)**2 + 1))) - c * y - d)

You can then plot this for various values of a,b,c,d.

Your function in general is called recurrence relation in the form

在此处输入图片说明

It can be solved numerically choosing starting value of y, then putting that into the equation, calculating next y value. And repeating the calculation putting next y value as previous y value into the equation. Calculations are repeated in a loop until y value converges. Y value may not converge. Even in this case you can analyze system further. You can try to plot graph y n = f(y n-1 ) and see what you've got. In case system is stable curve must be highly periodic and closed , otherwise non-converging system is chaotic and such equations you can throw out of the window.

Some examples of stable systems are Lissajous curves :

在此处输入图片说明

Some examples of chaotic systems are Rossler attractor :

在此处输入图片说明

y=A*sinh(-yC) analysis

To see if your system is stable or not - let's try to modulate sin(x) function with your hyperbolic sin recurrence relation : y=k*SIN(x)+0.88*SINH(-y-0.02) and let's try to draw this recurrence parametric chart of y prev vs y next .

k=0

在此处输入图片说明

Not much to see here, because in this case we get your original equation which has very low resolution between data points. They all lies along some line, with some small scattering which we can't differentiate with eyes - that's why we need sin(x) here !

k=0.0005

在此处输入图片说明

Much more interesting. Now it can be seen, that your "line" is not line at all and has some chaotic behavior. But let's look at something more appealing.

k=0.005

在此处输入图片说明

At some places sinh() recurrence wins, but at some - sin(). Let's try to force winning of sin() function, to be able to see if it will be modulated periodically and with a closed loop or not. So final image.

k=0.05

在此处输入图片说明

So, it's neither highly periodic, neither closed. We've got some type of attractor. Which means, that in a general case your equation behaves very chaotically and as such it's not worth a penny. Of course in your exact given parameters range it may behave as a linear function. But infinitesimal small segment of a circle also reassembles a line, what does it mean ? Nothing. You can't rely on a very specific input range. If your business unit will change requirements even a bit - behavior of your equation will change drastically. So the only rational step is to through it out of the window and re-build different - this time stable - model for a data. Or just state that it can't be done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM