简体   繁体   English

如何求解函数y = f(x,y),即函数值取决于自身

[英]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. 我想在python中解决以下方程式。 Problem is the dependent variable 'y' is also present in the right hand side of the equation as well. 问题是因变量“ y”也出现在等式的右侧。 First question, how is such equations named in mathematics? 第一个问题,在数学中如何命名这些方程式?

I can solve it if I skip the 'y' from the RHS. 如果我跳过RHS中的“ y”,就可以解决。 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 我使用以下代码:从matplotlib导入numpy作为np导入为plt pyplot

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. 设置y=0 ,求解方程,获取新y ,将新值插入RHS并重复该过程。 Track the value y(j)-y(j-1) to check the convergence. 跟踪值y(j)-y(j-1)以检查收敛性。 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) . 如果未过渡,请尝试将先前的RHS零件与具有一定权重的当前零件混合: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 图书:几个变量中非线性方程的迭代解法作者: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. 对于较大的间隔,它看起来更有趣,请注意参数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 . 您的方程式可以非常简化,以获得x作为y的函数。 First, we can rewrite your equation as follows: 首先,我们可以按如下方式重写您的方程式:

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

Note that this comes with some non-zero assumptions over A,B,C,D 请注意,这带有一些关于A,B,C,D的非零假设

b * x + c * y + d = arcsinh(y/a) 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))) 可以使用自然对数重写arcsinh :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) 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. 然后,您可以针对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. 可以通过数值选择y的起始值进行求解,然后将其放入方程中,然后计算下一个y值。 And repeating the calculation putting next y value as previous y value into the equation. 然后重复计算,将下一个y值作为先前的y值放入方程中。 Calculations are repeated in a loop until y value converges. 循环重复计算,直到y值收敛为止。 Y value may not converge. Y值可能不会收敛。 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. 您可以尝试绘制图y n = f(y n-1 )并查看得到的结果。 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 : 混沌系统的一些例子是Rossler吸引子

在此处输入图片说明

y=A*sinh(-yC) analysis y = A * sinh(-yC)分析

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 . 要查看您的系统是否稳定-让我们尝试使用双曲线正递归关系来调制sin(x)函数: y=k*SIN(x)+0.88*SINH(-y-0.02)并尝试绘制此y=k*SIN(x)+0.88*SINH(-y-0.02) y prev vs y next的递归参数图。

k=0 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 ! 它们全都沿着一条线分布,并带有一些我们无法用眼睛分辨的小散射-这就是为什么我们在这里需要sin(x)的原因!

k=0.0005 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 K = 0.005

在此处输入图片说明

At some places sinh() recurrence wins, but at some - sin(). 在某些地方,sinh()复发是成功的,但在某些地方-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. 让我们尝试强制赢得sin()函数,以便能够查看它是否会定期进行调制以及是否具有闭环。 So final image. 所以最终的形象。

k=0.05 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. 或者只是说这是不可能完成的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Scipy interp2d函数产生z = f(x,y),我想求解x - Scipy interp2d function produces z = f(x,y), I would like to solve for x 试图找到所有有序对(x,y),使得f(x,y)= 0且g(x,y)= 0; 即,我正在尝试找到多变量函数的根 - Trying to find all ordered pairs (x,y) such that f(x,y) = 0 and g(x,y) = 0; i.e., I'm trying to find the roots of a multi-variable function 如何集成一个 function w.r.t 时间; 即'y'是一个数组,时间(t)的值在1到3000之间变化 - How to integrate a function w.r.t time; i.e 'y' is an array and values of time(t) is varying from 1 to 3000 我如何绘制函数我无法在 x 或 y 中指定 x 或 y 值 - how I can draw function I can't specify x or y value in x or y 如何在同意的情况下解决y =(x + 1)** 3 -2? - How can I solve y = (x+1)**3 -2 for x in sympy? 如何允许用户使用数字输入从列表中选择文件? (即文件 x 为“1”,文件 y 为“2”等) - How can I allow a user to select a file from a list using number inputs? (I.e "1" for file x, "2" for file y, etc.) 我们如何编写一个 function `f`,它返回一个 integer 使得 `f(x) == f(y)` 当且仅当 `x` 和 `y` 相同? - How can we write a function `f` which returns an integer such that `f(x) == f(y)` if and only if `x` and `y` are the same? 如何在两个单独列表中的 X 和 Y 值范围内计算函数 f(X,Y) 的值 - How to compute values of function, f(X,Y), over a range of values of X and Y in two separate lists 如何编写向量函数来应用操作 f(x,y)? - How to write a vector function to apply operation f(x,y)? 如何找到映射 f: X -> Y 来表征 2 个时间序列 X 和 Y 之间的关系? - How do I find a mapping f : X -> Y to characterize the relationship between 2 time-series X and Y?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM