Ask Your Question
1

How to show that two given functions are linearly dependent

asked 2021-03-26 17:36:04 +0200

Presto.creator gravatar image

Is there a way with sage to show if two given functions are linearly dependent? Like if I have

f(x) = 17, g(x) = cos^2(x), h(x) = cos(2x)

Then sage could either give me the constants that would show they are linearly dependent, or say they aren't

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-03-27 01:04:58 +0200

Juanjo gravatar image

updated 2021-03-27 01:06:21 +0200

Let $f_1,\ldots,f_n$ be functions defined on a given interval $I$ and $n-1$ times differentiable. Let $W(f_1,\ldots,f_n)$ be the Wronskian of these functions. It is well known that:

if $f_1,\ldots,f_n$ are linearly dependent on $I$, then $W(f_1,\ldots,f_n)$ vanishes on $I$.

In general, the converse is not true: the vanishing of the Wronskian on $I$ does not imply that the functions are linearly dependent. However, if $f_1,\ldots,f_n$ are analytic, then these functions are linearly dependent on $I$ if and only if $W(f_1,\ldots,f_n)\equiv 0$ on $I$.

Since $f(x)=17$, $g(x)=\cos^2(x)$ and $h(x)=\cos(2x)$ are analytic on $\mathbb{R}$, we can check if they are linearly dependent by testing their Wronskian:

sage: f(x) = 17 
sage: g(x) = cos(x)^2 
sage: h(x) = cos(2*x) 
sage: funs = [f(x),g(x),h(x)] 
sage: bool(wronskian(*funs,x)==0)                                               
True

Thus, $f$, $g$ and $h$ are linearly dependent.

edit flag offensive delete link more
1

answered 2021-03-26 18:29:21 +0200

slelievre gravatar image

updated 2021-03-26 23:00:40 +0200

First an answer for the special case, then a more general answer.

Trigonometric functions

In the special case of the example in the question, this helps:

sage: f(x) = 17
sage: g(x) = cos(x)^2
sage: h(x) = cos(2*x)

sage: h(x).simplify_trig()
2*cos(x)^2 - 1

Linear independence of functions

Returning to the general question, one way to check for possible linear dependence relations, or for proofs of independence, would be to project to a finite-dimensional subspace and check there.

Form a vectors from the value of each function at a chosen collection of evaluation points.

If these vectors are linearly independent, then the functions are.

If there is a linear relation between these vectors, then it's worth checking if the linear relation in fact holds for the functions themselves.

Let us illustrate with the three functions above.

Choose a collection of evaluation points:

sage: xx = (0, pi/6, pi/4, pi/3, pi/2)

Form a vector for each function:

sage: u = vector([f(x) for x in xx])
sage: v = vector([g(x) for x in xx])
sage: w = vector([h(x) for x in xx])

To look for dependence relations, compute the left kernel of the matrix with these vectors as rows.

sage: m = matrix([u, v, w])
sage: K = m.kernel()
sage: K
Vector space of degree 3 and dimension 1 over Algebraic Real Field
Basis matrix:
[  1 -34  17]

This suggests that maybe f - 34*g + 17*h is zero.

Extract the coefficients:

sage: a, b, c = K.basis()[0]
sage: a, b, c
(1, -34, 17)

Check if the linear relation in fact holds for the functions:

sage: bool(a*f(x) + b*g(x) + c*h(x) == 0)
True
edit flag offensive delete link more

Comments

Thank you so much!

Presto.creator gravatar imagePresto.creator ( 2021-03-26 21:35:47 +0200 )edit

Hi again! I tried using the method you showed, but instead of getting a clean answer, I get "unable to convert pi to an element of Algebraic Real Field"

using

 f(x)=6*x
g(x)=2*x^2
h(x)=6*x-5*x^2
xx=(0,pi/6,pi/4,pi/3,pi/2)
u=vector(AA,[f(x) for x in xx])
v=vector(AA,[g(x) for x in xx])
w=vector(AA,[h(x) for x in xx])
m=matrix([u,v,w])
K=m.kernel()
show(K)

Any thoughts on if I did the code wrong?

Presto.creator gravatar imagePresto.creator ( 2021-03-26 21:48:11 +0200 )edit
1

You did nothing wrong.

Choosing xx = (0, pi/6, pi/4, pi/3, pi/2) gave algebraic values for the cosines so my original answer hardcoded constructing vectors over the algebraic numbers.

Using vector([...]) (as in edited answer) instead of vector(AA, [...]) (as in original answer) works both for original example and new one.

slelievre gravatar imageslelievre ( 2021-03-26 23:06:12 +0200 )edit

Is there a way to have it show a clean answer, like in your first reply to my question instead of something like

Vector space of degree 3 and dimension 1 over Symbolic Ring
Basis matrix:
[                            1 -15/2/(pi + (7*pi - pi^2)/pi)    -5/(pi + (7*pi - pi^2)/pi)]

I know that might be one answer but it's not helpful when finding non-trivial linear combinations lol

Presto.creator gravatar imagePresto.creator ( 2021-03-27 01:02:05 +0200 )edit

For three functions that are polynomials with integer coefficients, xx = (0, 1, 2, 3, 4, 5) might be a more natural choice of evaluation points.

slelievre gravatar imageslelievre ( 2021-03-27 12:34:15 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-03-26 17:36:04 +0200

Seen: 1,140 times

Last updated: Mar 27 '21