how to separate variables of f(x,y)?

17 vues (au cours des 30 derniers jours)
alireza seyfi
alireza seyfi le 17 Oct 2020
Commenté : alireza seyfi le 18 Oct 2020
I have a separable function f(x,y).how can i separate variables and have the function f as f(x,y)=g(x)*h(y) in MATLAB?
for example when f(x,y)=x^2*y^2 im looking for a way to have g(x)=x^2 and h(y)=y^2.
thank you for taking time to answer
sorry for my bad english

Réponses (1)

John D'Errico
John D'Errico le 17 Oct 2020
Modifié(e) : John D'Errico le 18 Oct 2020
In a completely general sense, if you do not know IF the functions can be separated, then no it is probably impossible to do for a black box function f(x,y).
Do you ABSOLUTELY know the function can be split into pieces? Then my response is still a qualified no, since there is no unique solution. That is, suppose you find a solution such that g(x)*h(y) == f(x,y)?
Then it is also true that (g(x)*k)*(h(y)/k) is as fully valid a solution, for ANY non-zero, finite value of k.
So there is never a unique solution. But that is not really a problem. So how can we construct the solution?
If you ABSOLUTELY know a solution exists, and you are willing to accept any arbitrary solution based on the above argument, then you next need to supply a point (x0,y0), such that neither g(x) or h(y) is zero or singular. If you cannot find such a point, then you are in trouble. So suppose one exists. Any point will suffice.
We will arbritraily choose a scaling such that h(y0) == 1. Now, consider the function
g = @(x) f(x,y0);
If f is truly separable, then this is a function only of x.
Now, we can create a function h(y).
h = @(y) f(x0,y)/g(x0);
I can safely use / there, since we assume g(x) is scalar valued for scalar input x.
You should see this construction creates new functions. It is valid as long as my asssumptions hold true, i.e., the point (x0,y0) avoids any singularities or zeros of the function f, and that f(x,y) is truly separable.
For example, is h(y0) == 1? We know that
h(y0) = f(x0,y0) / g(x0) = f(x0,y0) / f(x0,y0) == 1
that is valid as long as you have chosen the point (x0,y0) as I indicated.
Can we use that construction for some arbitrary separable fnunction f(x,y)? I'll use symbolic tools to convince you it works.
syms x y
f = (x^2+1)*sin(y);
Now, clearly (x0,y0) == (0,pi/4) is a satisfactory point. There are no singularities or zeros in g or in h there.
x0 = 0;
y0 = pi/4;
g = subs(f,y,y0)
g =
(2^(1/2)*(x^2 + 1))/2
h = subs(f,x,x0)/subs(g,x0)
h =
2^(1/2)*sin(y)
There is a factor of sqrt(2) in there that will cancel out. As you can see, h(pi/4) is 1. Of course, had I been smarter since I know the functional forms in this, I could have chosen the point (x0,y0) as (0,pi/2), because I know that sin(pi/2) is 1. And that will recover g and h a little more cleanly.
x0 = 0;
y0 = pi/2;
g = subs(f,y,y0)
g =
x^2 + 1
h = subs(f,x,x0)/subs(g,x0)
h =
sin(y)
This also shows that g and h are not uniquely specified.
Again, as long as a solution exists, and we choose (x0,y0) wisely, this is provably valid, Be careful though, as there are cases where it will fail if you choose poorly for (x0,y0). Thus, consider what happens in my construction if f(x0,y0) == 0.
  2 commentaires
John D'Errico
John D'Errico le 18 Oct 2020
Modifié(e) : John D'Errico le 18 Oct 2020
As I look back, I sincerely hope this is not a homework question from your real analysis course. If it is, then I'll never answer another question from you again.
alireza seyfi
alireza seyfi le 18 Oct 2020
The function that the user enters must be separable.
I'm looking for when user enters f(x,y) (like x*y or exp^x+y or sin(x)*cos(y)) I want to have the product of two functions in terms of x and y (like h(x)=x,g(y)=y h(x)=exp^x,g(y)=exp^y h(x)=sin x,g(y)=cos y )
Your answer was not what I was looking for.
I consider the integral equation g(s)=f(s)+landa*integral(k(s,t)*g(t),a,b), and assume that k(s,t) is separable.To determine eigenvalues I need to have the product of two functions in terms of s and t.
I know it is not easy and I wanted to know is there a way?

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by